Node.js 在使用azure web app部署的express angular 5应用程序上不允许使用405方法

Node.js 在使用azure web app部署的express angular 5应用程序上不允许使用405方法,node.js,azure,azure-web-app-service,angular5,Node.js,Azure,Azure Web App Service,Angular5,我使用azure web app部署了angular+nodejs应用程序,但在尝试访问我的节点api时出现405 method not allowed错误 server.js静态资产代码 /*API routes*/ const api = require("./server/routes/route"); /*Enable cors origin*/ var corsOptions = { "origin": "*", "methods": "GET,HEAD,PUT,PATCH,

我使用azure web app部署了angular+nodejs应用程序,但在尝试访问我的节点api时出现405 method not allowed错误

server.js静态资产代码

/*API routes*/
const api = require("./server/routes/route");

/*Enable cors origin*/
var corsOptions = {
  "origin": "*",
  "methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
  "preflightContinue": false,
  "optionsSuccessStatus": 204
}
app.use(cors(corsOptions));

app.use(express.static(path.join(__dirname, "/dist")));

app.use("/api", api);

app.get("/", function(req, res) {
  res.sendfile(path.join(__dirname, "/dist/index.html"));
});
由于我使用的是iis,所以我在dist文件夹的根目录中添加了一个web.config作为本文的要点

我的json看起来像这样

"apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": ["assets", "favicon.ico"],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app"...}]

最后,我的索引基href是

您需要确保
web.config
文件放在应用程序的根目录中(
D:\home\site\wwwroot

根据您的
web.config
,您的文件夹结构应该如下所示:

D:\home\site\wwwroot
├── node_modules 
│   └── ...
├── public
│   └── ...
├── server.js
├── package.json
└── web.config
实际上,在server.js文件中不再需要这些行:

// remove these lines of the code as well
app.use(express.static(path.join(__dirname, "/dist")));

app.get("/", function(req, res) {
  res.sendfile(path.join(__dirname, "/dist/index.html"));
});
现在,您可以使用此端点访问快速路线:

https://{yourWebAppName}.azurewebsites.net/api/{routeName}

并检索具有此端点的静态文件:

https://{yourWebAppName}.azurewebsites.net/{theFileInPublic}


所以我必须通过ftp添加它们?如果我在dist root中添加一个web.config,vs代码中的azure应用程序扩展不会这样做吗?在这种情况下,如果我的应用程序计划是基本的,我会从azure获取ftp详细信息吗?请参阅获取ftp详细信息,或者您可以使用Kudu cmd(https://.scm.azurewebsites.net/DebugConsole)要操作应用程序的远程文件。我尝试在wwwroot文件夹中添加web.config,但出现“未找到页面”错误。我的dist文件夹中的所有文件也在wwwroot文件夹中。顺便问一下,我应该在src/index.html中添加reference server.js吗??src是我拥有客户端应用程序文件的文件夹。不,你不应该。基于web.config中的这一行
,您需要将静态文件放入
/public
文件夹中,或者将
src
重命名为
public
。因此,我应该在wwwroot中创建一个名为public的文件夹,并将文件放入其中??
D:\home\site\wwwroot
├── node_modules 
│   └── ...
├── public
│   └── ...
├── server.js
├── package.json
└── web.config
// remove these lines of the code as well
app.use(express.static(path.join(__dirname, "/dist")));

app.get("/", function(req, res) {
  res.sendfile(path.join(__dirname, "/dist/index.html"));
});