簡體   English   中英

我可以用來訪問Expess應用程序(nodejs)的URL是什么

[英]What is the url with which I can access my expess app (nodejs)

我已經使用ssh訪問權限在GoDaddy上部署了Nodejs Express應用,以配置整個過程。 但是我找不到將我引向應用程序的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”將使我可以訪問該應用程序,但顯然不能,我想知道如何訪問它。

您可能必須先打開端口。 取決於您使用的方式,使用類似Linux的OS和ufw,您可以執行此操作

須藤ufw允許3000

您可以在此處找到更多信息和文檔:

ufw-簡單的防火牆

使用GoDaddy虛擬機的IP地址。 按照以下說明找到它:

  1. 登錄到您的GoDaddy帳戶。
  2. 在“我的產品”頁面中,單擊服務器。
  3. 在要使用的服務器旁邊,單擊管理。 服務器IP地址顯示在
  4. 詳細信息標簽。 您可能需要向下滾動以查看列表中的地址。

Usege:

http://youripaddress:3000

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM