我将在路由文件夹中有多个 API,我应该将它们放在同一个文件 API 中还是将它们分开?
├── app.js
├── src/
│ ├── contants/
│ ├── helpers/
│ ├── models/
│ ├── routes/
| | |___index.js
|___api.js
│ └── libs/
│ ├── backbone/
│ ├── underscore/
│ └── ...
api.js file contains all the APIs
const jwt = require("jsonwebtoken")
const axios = require("axios")
require("express-async-errors")
const bodyParser = require("body-parser")
const fs = require("fs")
const LOLTrackingSystem = require("../methods/onlineGamesTracking/LOLTracking")
const getUserData = require("../methods/leagueOfLegends/getUserData")
const isAuthenticated = require("../helpers/authenticated")
const apiRoute = (api) => {
api.use(bodyParser.json())
api.use(bodyParser.urlencoded({
extended: false
}));
api.post("/api/auth", (req, res) => {
//API Functions
})
api.post("/api/gizmo/memberProfile", isAuthenticated, (req, res) => {
//API Functions
})
api.post("/api/gizmo/memberState/:userId/:host/:state", async (req, res) => {
//API Functions
})
}
module.exports = apiRoute
我做的对吗?
如果它是错误的,那么正确的方法是什么?