简体   繁体   English

Node.js在本地工作,但远程返回“错误请求”

[英]Node.js works locally but returns “Bad request” remotely

I created an app (Node.js + Express), run it locally. 我创建了一个应用程序(Node.js + Express),在本地运行。 Then I created Node.js app at Azure and uploaded files through FTP. 然后,我在Azure上创建了Node.js应用程序,并通过FTP上传了文件。 And then I stuck - how to run it? 然后我卡住了-如何运行?

I found kind of remote console in azure and installed all the packages from there. 我在azure中找到了一种远程控制台,并从那里安装了所有软件包。 But when I tried to run the app: "npm start" I had only one line back: " Bad request ". 但是,当我尝试运行该应用程序:“ npm start”时,我只有一行返回:“ Bad request ”。 What does it mean? 这是什么意思? What to do with it? 怎么办呢?

The beginning of ./bin/www file: ./bin/www文件的开头:

var app = require('../app');
var debug = require('debug')('goWeb:server');
var http = require('http');

/**
 * Get port from environment and store in Express.
 */

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
 * Create HTTP server.
 */

var server = http.createServer(app);

/**
 * Listen on provided port, on all network interfaces.
 */

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

goWeb - is my app, mentioned in package.js. goWeb-是我的应用程序,在package.js中提到。

UPD I changed port to 80 and now I have the error "Port 80 requires elevated privileges". UPD我将端口更改为80,现在出现错误“端口80需要提升的特权”。 I have no idea what to do next. 我不知道下一步该怎么做。 Thanks 谢谢

It seems that your app.js file is not in wwwroot folder where the content is served by the web server iisnode and you don't need to do npm start in Azure web apps. 看来您的app.js文件不在Web服务器iisnode负责提供内容的wwwroot文件夹中,并且您不需要在Azure Web应用程序中执行npm start

You can take a look at my wwwroot structure, it looks like this: 您可以看一下我的wwwroot结构,如下所示: 在此处输入图片说明

You can also customize the path of the app.js file with the following lines in web.config . 您还可以使用web.config的以下行来自定义app.js文件的路径。

<handlers>
    <!-- Indicates that the app.js file is a node.js site to be handled by the iisnode module -->
    <add name="iisnode" path="app.js" verb="*" modules="iisnode"/>
</handlers>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM