这是我使用 typescript 3.7.4 的 Express 应用程序的以下代码:
import bodyParser from "body-parser";
import config from "config";
import cookieParser from "cookie-parser";
import express from "express";
import mongoose from "mongoose";
import path from "path";
export default class App {
public app: express.Application;
constructor() {
this.app = express();
this.initializeMiddlewares();
}
public listen(port: any) {
this.app.listen(port, () => {
console.log(`App listening on the port ${port}`);
});
}
public initializeControllers(controllers: any) {
controllers.forEach((controller: any) => {
this.app
.use(bodyParser.json())
.use(bodyParser.urlencoded())
.use("/", controller.router);
});
}
}`
Run Code Online (Sandbox Code Playgroud)
请帮我解决这部分代码。我不明白,当我发送帖子请求时,为什么我在 request.body 中未定义。