Azure Functions
Use the Azure Functions Adapter to run HttpRouter on Azure Functions V4 with Node.js 18+.
1. Install the CLI
To create an Azure Function, you must first install Azure Functions Core Tools.
On macOS:
brew tap azure/functions
brew install azure-functions-core-tools@4
2. Initialize the project
-
Create the project:
func init --typescript -
Install dependencies:
npm install @daiso-tech/core hono @marplex/hono-azurefunc-adapter -
Change the default route prefix in
host.json:{
"extensions": {
"http": {
"routePrefix": ""
}
}
}infoThe default Azure Functions route prefix is
/api. If you don't change it, start all your routes with/api.
3. Create the application
// src/app.ts
import {
HttpRouter,
HttpRes,
defaultHttpRouterAdapter,
} from "@daiso-tech/core/http-router";
const router = new HttpRouter({ router: defaultHttpRouterAdapter });
router.endpoint({
url: "/hello",
method: "GET",
handler: async () => HttpRes.text("Hello Azure Functions!"),
});
export default router;
// src/functions/httpTrigger.ts
import { app } from "@azure/functions";
import { azureHonoHandler } from "@marplex/hono-azurefunc-adapter";
import honoApp from "../app";
app.http("httpTrigger", {
methods: ["GET", "POST", "DELETE", "PUT", "PATCH"],
authLevel: "anonymous",
route: "{*proxy}",
handler: azureHonoHandler((request: Request) => honoApp.fetch(request)),
});
File structure
.
├── src
│ ├── app.ts
│ └── functions
│ └── httpTrigger.ts
├── package.json
├── host.json
└── tsconfig.json
4. Develop
npm run start
Access http://localhost:7071 in your browser.
5. Deploy
npm run build
func azure functionapp publish <YourFunctionAppName>
info
Before deploying, create the supporting Azure resources. See the Microsoft documentation.
Reference: Hono on Azure Functions