2020-02-03 10:24:25 +01:00
|
|
|
const Router = require("@koa/router")
|
2020-05-07 11:53:34 +02:00
|
|
|
const authenticated = require("../middleware/authenticated")
|
|
|
|
const compress = require("koa-compress")
|
|
|
|
const zlib = require("zlib")
|
2020-05-11 16:42:42 +02:00
|
|
|
const { budibaseAppsDir } = require("../utilities/budibaseDir")
|
2020-10-26 18:49:33 +01:00
|
|
|
const { isDev } = require("../utilities")
|
2020-02-03 10:24:25 +01:00
|
|
|
const {
|
2020-05-04 18:13:57 +02:00
|
|
|
authRoutes,
|
2020-04-06 15:05:57 +02:00
|
|
|
pageRoutes,
|
2020-11-04 13:36:38 +01:00
|
|
|
screenRoutes,
|
2020-04-06 15:05:57 +02:00
|
|
|
userRoutes,
|
2020-06-29 11:27:38 +02:00
|
|
|
deployRoutes,
|
2020-05-04 18:13:57 +02:00
|
|
|
applicationRoutes,
|
2020-10-09 20:10:28 +02:00
|
|
|
rowRoutes,
|
2020-10-09 19:49:23 +02:00
|
|
|
tableRoutes,
|
2020-05-04 18:13:57 +02:00
|
|
|
viewRoutes,
|
|
|
|
staticRoutes,
|
2020-05-07 11:53:34 +02:00
|
|
|
componentRoutes,
|
2020-09-21 14:49:34 +02:00
|
|
|
automationRoutes,
|
2020-05-21 15:31:23 +02:00
|
|
|
accesslevelRoutes,
|
2020-07-06 09:07:29 +02:00
|
|
|
apiKeysRoutes,
|
2020-09-28 18:04:08 +02:00
|
|
|
templatesRoutes,
|
2020-09-29 17:23:34 +02:00
|
|
|
analyticsRoutes,
|
2020-10-22 18:48:32 +02:00
|
|
|
webhookRoutes,
|
2020-11-12 18:06:55 +01:00
|
|
|
routingRoutes,
|
2020-05-07 11:53:34 +02:00
|
|
|
} = require("./routes")
|
2019-06-28 23:59:27 +02:00
|
|
|
|
2020-05-07 15:04:32 +02:00
|
|
|
const router = new Router()
|
2020-05-14 16:12:30 +02:00
|
|
|
const env = require("../environment")
|
2020-05-07 15:04:32 +02:00
|
|
|
|
|
|
|
router
|
|
|
|
.use(
|
|
|
|
compress({
|
|
|
|
threshold: 2048,
|
|
|
|
gzip: {
|
|
|
|
flush: zlib.Z_SYNC_FLUSH,
|
|
|
|
},
|
|
|
|
deflate: {
|
|
|
|
flush: zlib.Z_SYNC_FLUSH,
|
|
|
|
},
|
2020-05-18 15:58:39 +02:00
|
|
|
br: false,
|
2020-05-06 21:29:47 +02:00
|
|
|
})
|
2020-05-07 15:04:32 +02:00
|
|
|
)
|
|
|
|
.use(async (ctx, next) => {
|
|
|
|
ctx.config = {
|
2020-05-11 16:42:42 +02:00
|
|
|
latestPackagesFolder: budibaseAppsDir(),
|
2020-05-14 16:12:30 +02:00
|
|
|
jwtSecret: env.JWT_SECRET,
|
2020-06-03 13:29:42 +02:00
|
|
|
useAppRootPath: true,
|
2020-04-08 17:57:27 +02:00
|
|
|
}
|
2020-10-26 18:49:33 +01:00
|
|
|
ctx.isDev = isDev()
|
2020-05-07 15:04:32 +02:00
|
|
|
await next()
|
2020-05-07 11:53:34 +02:00
|
|
|
})
|
2020-10-16 23:02:17 +02:00
|
|
|
.use("/health", ctx => (ctx.status = 200))
|
2020-05-07 15:04:32 +02:00
|
|
|
.use(authenticated)
|
|
|
|
|
|
|
|
// error handling middleware
|
|
|
|
router.use(async (ctx, next) => {
|
|
|
|
try {
|
|
|
|
await next()
|
|
|
|
} catch (err) {
|
2020-05-18 16:46:38 +02:00
|
|
|
ctx.log.error(err)
|
2020-05-07 15:04:32 +02:00
|
|
|
ctx.status = err.status || err.statusCode || 500
|
|
|
|
ctx.body = {
|
|
|
|
message: err.message,
|
|
|
|
status: ctx.status,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2020-04-08 17:57:27 +02:00
|
|
|
|
2020-11-10 18:08:02 +01:00
|
|
|
router.get("/health", ctx => (ctx.status = 200))
|
|
|
|
|
2020-05-07 15:04:32 +02:00
|
|
|
router.use(authRoutes.routes())
|
|
|
|
router.use(authRoutes.allowedMethods())
|
2020-05-04 18:13:57 +02:00
|
|
|
|
2020-05-07 15:04:32 +02:00
|
|
|
// authenticated routes
|
|
|
|
router.use(viewRoutes.routes())
|
|
|
|
router.use(viewRoutes.allowedMethods())
|
2020-04-14 16:14:57 +02:00
|
|
|
|
2020-10-09 19:49:23 +02:00
|
|
|
router.use(tableRoutes.routes())
|
|
|
|
router.use(tableRoutes.allowedMethods())
|
2020-04-13 12:47:53 +02:00
|
|
|
|
2020-10-09 20:10:28 +02:00
|
|
|
router.use(rowRoutes.routes())
|
|
|
|
router.use(rowRoutes.allowedMethods())
|
2020-06-11 15:35:45 +02:00
|
|
|
|
2020-05-07 15:04:32 +02:00
|
|
|
router.use(userRoutes.routes())
|
|
|
|
router.use(userRoutes.allowedMethods())
|
2020-04-07 16:12:08 +02:00
|
|
|
|
2020-09-21 14:49:34 +02:00
|
|
|
router.use(automationRoutes.routes())
|
|
|
|
router.use(automationRoutes.allowedMethods())
|
2020-06-29 11:27:38 +02:00
|
|
|
|
2020-10-22 18:48:32 +02:00
|
|
|
router.use(webhookRoutes.routes())
|
|
|
|
router.use(webhookRoutes.allowedMethods())
|
|
|
|
|
2020-06-29 11:27:38 +02:00
|
|
|
router.use(deployRoutes.routes())
|
|
|
|
router.use(deployRoutes.allowedMethods())
|
2020-09-28 18:04:08 +02:00
|
|
|
|
|
|
|
router.use(templatesRoutes.routes())
|
|
|
|
router.use(templatesRoutes.allowedMethods())
|
2020-05-07 15:04:32 +02:00
|
|
|
// end auth routes
|
2020-05-06 21:29:47 +02:00
|
|
|
|
2020-05-07 15:04:32 +02:00
|
|
|
router.use(pageRoutes.routes())
|
|
|
|
router.use(pageRoutes.allowedMethods())
|
2020-05-06 21:29:47 +02:00
|
|
|
|
2020-11-04 13:36:38 +01:00
|
|
|
router.use(screenRoutes.routes())
|
|
|
|
router.use(screenRoutes.allowedMethods())
|
|
|
|
|
2020-05-07 15:04:32 +02:00
|
|
|
router.use(applicationRoutes.routes())
|
|
|
|
router.use(applicationRoutes.allowedMethods())
|
2020-05-06 21:29:47 +02:00
|
|
|
|
2020-05-07 15:04:32 +02:00
|
|
|
router.use(componentRoutes.routes())
|
|
|
|
router.use(componentRoutes.allowedMethods())
|
2020-05-06 21:29:47 +02:00
|
|
|
|
2020-05-21 15:31:23 +02:00
|
|
|
router.use(accesslevelRoutes.routes())
|
|
|
|
router.use(accesslevelRoutes.allowedMethods())
|
|
|
|
|
2020-07-02 17:53:09 +02:00
|
|
|
router.use(apiKeysRoutes.routes())
|
|
|
|
router.use(apiKeysRoutes.allowedMethods())
|
|
|
|
|
2020-09-29 17:23:34 +02:00
|
|
|
router.use(analyticsRoutes.routes())
|
|
|
|
router.use(analyticsRoutes.allowedMethods())
|
|
|
|
|
2020-05-07 15:04:32 +02:00
|
|
|
router.use(staticRoutes.routes())
|
|
|
|
router.use(staticRoutes.allowedMethods())
|
2020-04-06 15:05:57 +02:00
|
|
|
|
2020-11-12 18:06:55 +01:00
|
|
|
router.use(routingRoutes.routes())
|
|
|
|
router.use(routingRoutes.allowedMethods())
|
|
|
|
|
2020-05-07 15:04:32 +02:00
|
|
|
router.redirect("/", "/_builder")
|
2019-06-28 23:59:27 +02:00
|
|
|
|
2020-05-07 15:04:32 +02:00
|
|
|
module.exports = router
|