我的expressjs路由正在使用localhost,但是当我将它上传到服务器时,路由不起作用,这是我的代码。
当我点击localhost:82 / api /然后它工作正常。但是当我 上传到服务器它不起作用,和控制台(“请求不 发现“)
const express = require('express');
const bodyParser = require('body-parser');
const api = require('./server/routes/api');
const cors=require('cors');
const app = express();
app.use(cors());
app.use('/api', api);
app.get('*', (req, res) => {
console.log("request not found");
});
const port = process.env.PORT || '82';
app.set('port', port);
app.listen(port,()=>{
console.log(`API running on localhost:${port}`);
});
//routes/api.js
const express = require('express');
const router = express.Router();
router.get('/', (req, res, next) => {
res.send("HI");
});
module.exports = router;