我使用azure部署了一个Web服务,当我尝试检查Web以查看是否正在工作时,我收到一条错误消息,我已经尝试添加一个指向我的index.js的web.config,并且似乎没有任何作用。 / p>
'use strict'
var app = require('./app');
var port = process.env.PORT || 3800;
//create server
app.listen(port, () =>{
console.log(`Listening Server http://localhost:${port}`);
})
这是我的index.js,在内部,我正在调用app.js来获取我需要的所有东西。
'use strict'
var express = require('express');
var bodyParser = require('body-parser');
var tediousExpress = require('express4-tedious');
var config = require('./connection');
var app = express();
//SQL server connection
app.use( (req, res, next) => {
req.sql = tediousExpress(config);
next();
})
//declare routes
var clients_routes = require('./routes/clients');
//middlewares
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
//cors
app.use(function(req, res, next){
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Authorization, X-API-KEY, X-Requested-With, Content-Type, Accept, Access-Control-Allow-Request-Me');
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE');
res.header('Allow', 'GET, POST, OPTIONS, PUT, DELETE');
next();
});
//routes
app.use('/api',clients_routes);
//export
module.exports = app;
这是我正在使用的web.config文件,azure站点上的部署直接来自github。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="index.js" verb="*" modules="iisnode" />
</handlers>
<iisnode node_env="production" />
<rewrite>
<rules>
<rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">
<match url="iisnode" />
</rule>
<rule name="DynamicContent">
<conditions>
<add input="{{REQUEST_FILENAME}}" matchType="IsFile" negate="True" />
</conditions>
<action type="Rewrite" url="index.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
当我使用Web服务时(我应该得到无法获取的/ GET或类似信息,这将告诉我Express正常工作,但我收到一条错误消息。