Веб-приложение Node.js Azure не может получить доступ к моим маршрутам. - PullRequest
0 голосов
/ 19 сентября 2018

У меня есть следующий index.js файл:

const express = require('express');
const app = express();
const router = express.Router();
var cors = require('cors');
var http = require('http').Server(app);
const fileUpload = require('express-fileupload');
app.use(fileUpload());
const uploadRoute = require('./routes/upload');

app.use(cors());

app.use(uploadRoute(router));
app.use(router);
http.listen(80, function () {
    console.log('listening on *:80');
});

И следующий файл web.config:

    <?xml version="1.0" encoding="utf-8"?>
<!--
     This configuration file is required if iisnode is used to run node processes behind
     IIS or IIS Express.  For more information, visit:

     https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->

<configuration>
  <system.webServer>
    <!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
    <webSocket enabled="false" />
    <handlers>
      <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
      <add name="iisnode" path="index.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>
        <!-- Do not interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^index.js\/debug[\/]?" />
        </rule>

        <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}"/>
        </rule>

        <!-- All other URLs are mapped to the node.js site entry point -->
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="index.js"/>
        </rule>
      </rules>
    </rewrite>

    <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
        </hiddenSegments>
      </requestFiltering>
    </security>

    <!-- Make sure error responses are left untouched -->
    <httpErrors existingResponse="PassThrough" />

    <!--
      You can control how Node is hosted within IIS using the following options:
        * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
        * node_env: will be propagated to node as NODE_ENV environment variable
        * debuggingEnabled - controls whether the built-in debugger is enabled

      See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
    -->
    <!--<iisnode watchedFiles="web.config;*.js"/>-->
  </system.webServer>
</configuration>

Теперь я добавляю это на свой сервер, что делает его похожим наэто:

enter image description here

Затем я пытаюсь запустить сервер, используя навсегда forever start index.js, затем я иду на свой веб-сайт и пробую маршрут, но он просто даетмне код ошибки 500.

Может кто-нибудь сказать мне, что я сделал не так?

1 Ответ

0 голосов
/ 20 сентября 2018

По моему опыту, вы можете изменить index.js, как показано ниже, и повторить попытку:

const express = require('express');
const app = express();
const router = express.Router();
var cors = require('cors');
var http = require('http').Server(app);
const fileUpload = require('express-fileupload');
app.use(fileUpload());
const uploadRoute = require('./routes/upload');

app.use(cors());

app.use(uploadRoute(router));
app.use(router);

app.set('port', process.env.PORT || 5000);

app.listen(app.get('port'), function(){
          console.log('Express server listening on port ' + app.get('port'));
          });

Кроме того, для ошибки 500 вам необходимо включить ведение журнала stdout и stderrдля устранения неполадок и посмотреть, что говорят журналы.Чтобы включить отладку, выполните следующие действия:

1) Создайте файл iisnode.yml в корневой папке (D:\home\site\wwwroot), если он не существует.

2) Добавьте в него следующие строки.

loggingEnabled: true
logDirectory: iisnode

После этого вы можете найти журналы в D:\home\site\wwwroot\iisnode.

Для получения дополнительной информации, пожалуйста, обратитесь к документ .

Надеюсь, это поможет вам.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...