首页 文章

express.js应用程序在localhost上运行,但不在托管站点上运行

提问于
浏览
1

我正在尝试将我的第一个wep页面部署到internt(在123-reg.com上) . 当我在localhost:3000上运行它时页面运行完美,但在尝试访问互联网时却完全没有 . 我收到以下错误;

您无权访问此服务器上的/ . Apache / 2.4.37(Unix)服务器,网址为www.themermaidclapton.com端口80

我认为问题出在我的app.listen()函数中 . 我尝试了很多变化,并在网上做了大量的研究,但我找不到解决方案 . 谁能指出我正确的方向?

var express = require('express');
var path = require("path");

app = express();

app.use(express.static('public'));
app.use('/public/js', express.static(path.join(__dirname, '/public/scripts')));

app.get('/', function(req, res){
    res.render(index.html);
});

app.listen(3000, function(){
    console.log("App has started");
});

1 回答

  • 0

    我认为问题出在港口 .

    app.listen(3000, function(){ console.log("App has started"); }); .

    因为您使用的是静态端口,所以您不知道它可以使用 . 所以这取决于 https://www.123-reg.co.uk/web-hosting/ docs .

    const port = process.env.PORT || 3000;
    
    app.listen(port, function(){
        console.log("App has started");
    });
    

    `

相关问题