1
0
Fork 0
mirror of synced 2024-06-30 12:00:31 +12:00
budibase/packages/server/src/api/controllers/dev.js

35 lines
849 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-03 19:31:09 +12:00
exports.redirectGet = async (ctx) => {
await redirect(ctx, "GET")
}
2021-05-03 19:31:09 +12:00
exports.redirectPost = async (ctx) => {
await redirect(ctx, "POST")
}
2021-05-03 19:31:09 +12:00
exports.redirectDelete = async (ctx) => {
await redirect(ctx, "DELETE")
}