部署到服务器后节点应用程序不工作

时间:2021-05-31 11:13:56

标签: node.js express router

我有在本地机器上正常运行的节点应用程序,但是当我将此应用程序部署到服务器时,只有“/”路由在工作,其他路由器不工作。

当我在本地机器上运行它时,它工作正常。

enter image description here

这是另一个例子

enter image description here

但是当我将它部署到服务器时,它不起作用 enter image description here

只有主路由在服务器上工作。

下面是我的 app.js

//routers : Masters
app.use('/masters', masterRoutes);     

app.get('/', (req, res, next) => {
    res.status(200).json('Application is up and running on port 4003');
});

并且我在“routes/masters.js”中添加了路由

router.get('/categories', categoryController.getCategories);

当我将它部署到服务器时,我也重新启动了 pm2。 4003端口也在服务器上打开。

我缺少什么?

1 个答案:

答案 0 :(得分:0)

问题已解决,Nginx 配置设置错误。 在如下位置后添加斜杠'/'

 location /_api/{
        proxy_pass "http://localhost:4003/";
 }
相关问题