improve route generation

This commit is contained in:
SrGooglo 2023-05-31 19:37:22 +00:00
parent bfdad744a4
commit 75adbc0c96

View File

@ -48,18 +48,20 @@ function createRoutesFromDirectory(startFrom, directoryPath, router) {
route = route.replace(".ts", "") route = route.replace(".ts", "")
route = route.replace(".tsx", "") route = route.replace(".tsx", "")
if (route === "index") { if (route.endsWith("/index")) {
route = "/" route = route.replace("/index", "")
} else {
route = `/${route}`
} }
route = `/${route}`
let handler = require(filePath) let handler = require(filePath)
handler = handler.default || handler handler = handler.default || handler
router[method](route, createRouteHandler(route, handler)) router[method](route, createRouteHandler(route, handler))
//console.log(`[ROUTE] ${method.toUpperCase()} [${route}]`, handler)
router.routes.push({ router.routes.push({
method, method,
path: route, path: route,