【发布时间】:2019-05-25 11:30:11
【问题描述】:
我已经在 GoDaddy 上部署了我的 Nodejs Express 应用程序,使用 ssh 访问来配置整个事情。但我找不到指向我的应用的 URL。
它在我的电脑上完美运行,我通过链接http://localhost:3000访问应用程序
const express = require("express");
const bodyParser = require("body-parser");
const httpRequest = require("request");
const app = new express();
const http = require("http").Server(app);
const io = require("socket.io")(http);
app.set("view engine","ejs");
var port = process.env.PORT || 3000;
app.use(express.static("public"));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
//headers
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', '*');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT,
PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
app.get("/",(request,response)=>{
response.send("hello world!");
});
http.listen(port,function(){
console.log(server.address());
console.log("listening on port "+port);
});
我有我的服务器的域名,我认为在它的末尾添加“:3000”可以让我访问该应用程序,但显然它没有,我想知道如何访问它。
【问题讨论】:
-
你的服务器操作系统是什么?是专用服务器吗?如果您的服务器是共享的,则 PORT 3000 或 env 中设置的任何端口。需要允许公共访问。您可以联系 GoDaddy 客户服务以启用该端口以供公众访问。
标签: node.js express url routing ip