1
0
Fork 0
mirror of synced 2024-07-13 18:26:06 +12:00
budibase/packages/server/src/api/controllers/dev.js

35 lines
843 B
JavaScript
Raw Normal View History

const fetch = require("node-fetch")
const env = require("../../environment")
const { checkSlashesInUrl } = require("../../utilities")
const { request } = require("../../utilities/workerRequests")
async function redirect(ctx, method) {
const { devPath } = ctx.params
const response = await fetch(
checkSlashesInUrl(`${env.WORKER_URL}/api/admin/${devPath}`),
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
}
2021-05-04 22:32:22 +12:00
exports.redirectGet = async ctx => {
await redirect(ctx, "GET")
}
2021-05-04 22:32:22 +12:00
exports.redirectPost = async ctx => {
await redirect(ctx, "POST")
}
2021-05-04 22:32:22 +12:00
exports.redirectDelete = async ctx => {
await redirect(ctx, "DELETE")
}