mirror of https://github.com/Budibase/budibase.git
9 changed files with 79 additions and 24 deletions
@ -0,0 +1,34 @@ |
|||
const fetch = require("node-fetch") |
|||
const env = require("../../environment") |
|||
const { checkSlashesInUrl } = require("../../utilities") |
|||
const { request } = require("../../utilities/workerRequests") |
|||
|
|||
async function redirect(ctx, method) { |
|||
const { path } = ctx.params |
|||
const response = await fetch( |
|||
checkSlashesInUrl(`${env.WORKER_URL}/api/admin/${path}`), |
|||
request(ctx, { |
|||
method, |
|||
body: ctx.request.body, |
|||
}) |
|||
) |
|||
ctx.body = await response.json() |
|||
const cookie = response.headers.get("set-cookie") |
|||
if (cookie) { |
|||
ctx.set("set-cookie", cookie) |
|||
} |
|||
ctx.status = response.status |
|||
ctx.cookies |
|||
} |
|||
|
|||
exports.redirectGet = async ctx => { |
|||
await redirect(ctx, "GET") |
|||
} |
|||
|
|||
exports.redirectPost = async ctx => { |
|||
await redirect(ctx, "POST") |
|||
} |
|||
|
|||
exports.redirectDelete = async ctx => { |
|||
await redirect(ctx, "DELETE") |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
const Router = require("@koa/router") |
|||
const controller = require("../controllers/dev") |
|||
const env = require("../../environment") |
|||
|
|||
const router = Router() |
|||
|
|||
if (env.isDev()) { |
|||
router.get("/api/admin/:path", controller.redirectGet) |
|||
router.post("/api/admin/:path", controller.redirectPost) |
|||
router.delete("/api/admin/:path", controller.redirectDelete) |
|||
} |
|||
|
|||
module.exports = router |
|||
Loading…
Reference in new issue