【发布时间】:2021-04-27 09:04:38
【问题描述】:
所以,我有一个非常简单的 Express.js 应用程序。我的入口点,server.js,转载如下。
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.status(200).send({ "message": "Welcome to the application. Express JS is outputting this JSON. " });
});
app.get('/all', (req, res) => {
res.status(200).send({ "message": "All the things. " });
});
app.listen(3000, () => {
console.log("Server is listening on port 3000");
});
当我使用命令node server.js 运行此程序时,它运行良好,我可以通过http://localhost:3000 访问该应用程序。同样,当我将其部署到 LAN 服务器时,我可以访问其 IP 并访问应用程序,如http://192.168.100.105:3000。
现在,如果我希望应用程序在http://192.168.100.105/app1 运行,该怎么办?一种方法是应用 Express 应用程序以在端口 80 上运行并重新配置所有路由以使用 app1 作为新的基本 URL,但我无权(或不能)覆盖应用程序在默认端口上运行。那么,有没有其他方法可以实现相同的目标 在端口80 上运行它?
【问题讨论】:
-
例如使用像nginx这样的代理?
标签: javascript node.js api express