budibase/packages/server/middleware/routes/authenticated.js

132 lines
3.1 KiB
JavaScript
Raw Normal View History

2020-04-03 18:35:20 +02:00
const Router = require("@koa/router");
2020-04-06 15:05:57 +02:00
const StatusCodes = require("../../utilities/statusCodes")
2020-04-03 17:15:53 +02:00
const routeHandlers = require("../routeHandlers")
const router = Router();
2020-04-06 15:05:57 +02:00
async function isAuthenticated(ctx, next) {
2020-04-03 17:15:53 +02:00
if (ctx.isAuthenticated) {
await next()
} else {
ctx.response.status = StatusCodes.UNAUTHORIZED
}
2020-04-06 15:05:57 +02:00
}
router.use(isAuthenticated)
2020-04-03 17:15:53 +02:00
router.post(
"/_builder/instance/:appname/:instanceid/api/upgradeData",
routeHandlers.upgradeData
)
router.post("/:appname/api/changeMyPassword", routeHandlers.changeMyPassword)
router.post(
"/_builder/instance/:appname/:instanceid/api/changeMyPassword",
routeHandlers.changeMyPassword
)
router.post(
"/:appname/api/executeAction/:actionname",
routeHandlers.executeAction
)
router.post(
"/_builder/instance/:appname/:instanceid/api/executeAction/:actionname",
routeHandlers.executeAction
)
router.post("/:appname/api/createUser", routeHandlers.createUser)
router.post(
"/_builder/instance/:appname/:instanceid/api/createUser",
routeHandlers.createUser
)
router.post("/:appname/api/enableUser", routeHandlers.enableUser)
router.post(
"/_builder/instance/:appname/:instanceid/api/enableUser",
routeHandlers.enableUser
)
router.post("/:appname/api/disableUser", routeHandlers.disableUser)
router.post(
"/_builder/instance/:appname/:instanceid/api/disableUser",
routeHandlers.disableUser
)
router.get("/:appname/api/users", routeHandlers.getUsers)
router.get(
"/_builder/instance/:appname/:instanceid/api/users",
routeHandlers.getUsers
)
router.get("/:appname/api/accessLevels", routeHandlers.getAccessLevels)
router.get(
"/_builder/instance/:appname/:instanceid/api/accessLevels",
routeHandlers.getAccessLevels
)
router.get("/:appname/api/listRecords/*", routeHandlers.listRecordsGet)
router.get(
"/_builder/instance/:appname/:instanceid/api/listRecords/*",
routeHandlers.listRecordsGet
)
router.post("/:appname/api/listRecords/*", routeHandlers.listRecordsPost)
router.post(
"/_builder/instance/:appname/:instanceid/api/listRecords/*",
routeHandlers.listRecordsPost
)
router.post("/:appname/api/aggregates/*", routeHandlers.aggregatesPost)
router.post(
"/_builder/instance/:appname/:instanceid/api/aggregates/*",
routeHandlers.aggregatesPost
)
router.post("/:appname/api/files/*", routeHandlers.postFiles)
router.post(
"/_builder/instance/:appname/:instanceid/api/files/*",
routeHandlers.postFiles
)
router.post("/:appname/api/record/*", routeHandlers.saveRecord)
router.post(
"/_builder/instance/:appname/:instanceid/api/record/*",
routeHandlers.saveRecord
)
router.get("/:appname/api/lookup_field/*", routeHandlers.lookupField)
router.get(
"/_builder/instance/:appname/:instanceid/api/lookup_field/*",
routeHandlers.lookupField
)
router.get("/:appname/api/record/*", routeHandlers.getRecord)
router.get(
"/_builder/instance/:appname/:instanceid/api/record/*",
routeHandlers.getRecord
)
router.del("/:appname/api/record/*", routeHandlers.deleteRecord)
router.del(
"/_builder/instance/:appname/:instanceid/api/record/*",
routeHandlers.deleteRecord
)
router.post("/:appname/api/apphierarchy", routeHandlers.saveAppHierarchy)
module.exports = router