我使用模型 v4 的 azure 函数
索引.ts
import { app } from "@azure/functions";
import azureFunctionHandler from "azure-aws-serverless-express";
import expressApp from "../../app";
app.http("httpTrigger1", {
methods: ["GET"],
route: "api/{*segments}",
handler: async (context, request) => {
console.log("context ::::: ", context);
console.log("request :::::: ", request);
return { body: `Hello` };
},
});
module.exports = azureFunctionHandler(expressApp);
应用程序.ts
import express, { Request, Response } from "express";
const app = express();
app.get("/api/user", (req: Request, res: Response) => {
res.send("Hello from Express!");
});
export default app;
我的快递应用程序
我正在尝试从azure函数执行express js API,似乎我收到了azure函数的响应,例如“Hello”,但我期望来自express的响应,例如“Hello from Express!”。
azure-aws-serverless-express
对于 Javascript 和 Typescript V3 模型 Azure 函数来说都完美无缺。
Typescript V3 功能-
index.ts-
import { AzureFunction, Context, HttpRequest } from "@azure/functions";
import azureFunctionHandler from "azure-aws-serverless-express";
import expressApp from "../app";
const httpTrigger: AzureFunction = function (context: Context, req: HttpRequest) {
azureFunctionHandler(expressApp)(context, req);
};
export default httpTrigger;
app.ts-
import express, { Request, Response } from "express";
const app = express();
app.get('/api/user', (req,res) => res.send("Hello from Express!"));
export default app;
function.json-
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
],
"route": "{*segments}"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "../dist/HttpTrigger1/index.js"
}
The "url" argument must be of type string. Received undefined
。此错误涉及包文件夹。