I have the following problem :
Im making a rest api but my app doesnt even go into the actions when I make a request to the endpoint ?
This is my server setup
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}`); });
Its my first time using the import syntax could it possibly be because of it ?
When I make a request GET localhost:3000/items it doesnt even go to the console.log
Tsconfig.json :
{ "compilerOptions": { "target": "es2016", "module": "commonjs", "outDir": "./dist", "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true, } }
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 }));
// You missing
app.use('/', indexRouter);
app.use('/users', usersRouter);
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}`);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.