NodeJS '/' 主路由有效,但其余路由无效(CPanel 共享主机)

NodeJS '/' home route is working but the remaining routes are not working (CPanel Shared Hosting)

我在 CPANEL 共享主机上部署 NodeJS API 时遇到问题。 我的应用程序在本地主机上运行良好,但是当我部署它时,主路由是唯一可用的路由,所有剩余路由均无效(500 内部错误)。我用快递。

const express = require('express');
const cors = require('cors');
const app = express();
require('dotenv').config();

// Import Routes
const productsRoute = require('./routes/products');

// Middleware
const corsOpts = {
  origin: '*',

  methods: ['GET', 'POST', 'PUT', 'DELETE'],

  allowedHeaders: ['Content-Type'],
};

app.use(cors(corsOpts));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());


app.use('/products', productsRoute);
app.get('/hello', (req, res) => res.send('Hello World !'));
app.get('/', (req, res) => {
  res.send("OK");
});

app.listen();

Cpanel configuration

有人可以帮助我吗?

谢谢!

我试了很多方法都解决了。这是乘客配置问题 在我生成的 .htaccess 文件中,我在顶部添加以下行

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /
RewriteRule ^server/(.*)?$ https://127.0.0.1:3000/ [P,L]

在我的 nodeJS 应用程序中,我监听端口 3000。