node.js - วิธีการใช้ express router ใน typescript?
ฉันกำลังพยายามแปลงโปรเจกต์เก่าเป็น TypeScript และมีปัญหาเกี่ยวกับการ routing ดูเหมือนว่ามันจะไม่รู้จัก routing ของไฟล์ย่อยตามที่ระบุในคำตอบของ SO นี้
app.ts
import express from "express";
const app = express();
import * as contentRouter from "./routes/content";
import * as blogRouter from "./routes/blog";
let router: express.Router = express.Router();
// All routing here
router.use("/content", contentRouter);
router.use("/blog", blogRouter);
// Export the router
export = router;
./routes/content.ts
import router from "../app"
router.get("/", (req, res) => {
res.send("Hello World!");
});
export default router
