我现在使用的是Express 4.18.3,我在想为什么我的请求正文不能被解析?
import express, { Express, Request, Response } from 'express'
import dotenv from 'dotenv'
import v1 from './routes/index'
dotenv.config()
const app: Express = express()
app.use('/', v1)
app.use(express.json())
app.use(express.urlencoded({
extended: true
})
const port = process.env.PORT || 3000
const startExpressServer = () => {
app.listen(port, () => {
console.log(`[server]: Server is running at http://localhost:${port}`)
})
}
startExpressServer()
Req.Body当前未定义. 我的要求是:
curl --location 'http://localhost:3000/user/login' \
--header 'Content-Type: application/json' \
--data '{
"apiKey": "test"
}'