我有以下问题:
我正在做一个API,但是当我向端点发出请求时,我的应用程序甚至没有进入操作?
这是我的服务器设置
import express, { Express } from 'express';
import cookieParser from 'cookie-parser';
import cors from 'cors';
import characterRouter from '../modules/character/router';
import userRouter from '../modules/user/router';
import itemsRouter from '../modules/item/router';
require('dotenv').config();
const app: Express = express();
app.use(cors);
//Setup cookieParser and public folder
app.use(cookieParser());
//Setup bodyParser
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.get('/items', (req, res) => {
console.log('OK');
res.json({ ok: true });
});
app.listen(3000, () => {
console.log(`Server listnening on port ${process.env.SERVER_PORT}`);
});
这是我第一次使用导入语法,可能是因为它吗?
当我请求GET localhost:3000/items时,它甚至不会转到console.log
子配置:
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
}
}
1条答案
按热度按时间a8jjtwal1#