1
0
Fork 0
mirror of synced 2024-10-02 10:08:09 +13:00

Fix dev app preview return url

This commit is contained in:
Rory Powell 2022-01-13 16:29:55 +00:00
parent 3d7923cb16
commit 13d0bfb190
5 changed files with 46 additions and 12 deletions

View file

@ -8,6 +8,7 @@ exports.Cookies = {
Auth: "budibase:auth", Auth: "budibase:auth",
Init: "budibase:init", Init: "budibase:init",
OIDC_CONFIG: "budibase:oidc:config", OIDC_CONFIG: "budibase:oidc:config",
RETURN_URL: "budibase:returnurl",
} }
exports.Headers = { exports.Headers = {

View file

@ -96,7 +96,12 @@ exports.getCookie = (ctx, name) => {
* @param {string|object} value The value of cookie which will be set. * @param {string|object} value The value of cookie which will be set.
* @param {object} opts options like whether to sign. * @param {object} opts options like whether to sign.
*/ */
exports.setCookie = (ctx, value, name = "builder", opts = { sign: true }) => { exports.setCookie = (
ctx,
value,
name = "builder",
opts = { sign: true, requestDomain: false }
) => {
if (value && opts && opts.sign) { if (value && opts && opts.sign) {
value = jwt.sign(value, options.secretOrKey) value = jwt.sign(value, options.secretOrKey)
} }
@ -108,7 +113,7 @@ exports.setCookie = (ctx, value, name = "builder", opts = { sign: true }) => {
overwrite: true, overwrite: true,
} }
if (environment.COOKIE_DOMAIN) { if (environment.COOKIE_DOMAIN && !opts.requestDomain) {
config.domain = environment.COOKIE_DOMAIN config.domain = environment.COOKIE_DOMAIN
} }

View file

@ -43,8 +43,8 @@ const coreFields = {
enum: Object.values(BodyTypes), enum: Object.values(BodyTypes),
}, },
pagination: { pagination: {
type: DatasourceFieldTypes.OBJECT type: DatasourceFieldTypes.OBJECT,
} },
} }
module RestModule { module RestModule {
@ -178,12 +178,17 @@ module RestModule {
headers, headers,
}, },
pagination: { pagination: {
cursor: nextCursor cursor: nextCursor,
} },
} }
} }
getUrl(path: string, queryString: string, pagination: PaginationConfig | null, paginationValues: PaginationValues | null): string { getUrl(
path: string,
queryString: string,
pagination: PaginationConfig | null,
paginationValues: PaginationValues | null
): string {
// Add pagination params to query string if required // Add pagination params to query string if required
if (pagination?.location === "query" && paginationValues) { if (pagination?.location === "query" && paginationValues) {
const { pageParam, sizeParam } = pagination const { pageParam, sizeParam } = pagination
@ -217,14 +222,22 @@ module RestModule {
return complete return complete
} }
addBody(bodyType: string, body: string | any, input: any, pagination: PaginationConfig | null, paginationValues: PaginationValues | null) { addBody(
bodyType: string,
body: string | any,
input: any,
pagination: PaginationConfig | null,
paginationValues: PaginationValues | null
) {
if (!input.headers) { if (!input.headers) {
input.headers = {} input.headers = {}
} }
if (bodyType === BodyTypes.NONE) { if (bodyType === BodyTypes.NONE) {
return input return input
} }
let error, object: any = {}, string = "" let error,
object: any = {},
string = ""
try { try {
if (body) { if (body) {
string = typeof body !== "string" ? JSON.stringify(body) : body string = typeof body !== "string" ? JSON.stringify(body) : body
@ -333,7 +346,7 @@ module RestModule {
requestBody, requestBody,
authConfigId, authConfigId,
pagination, pagination,
paginationValues paginationValues,
} = query } = query
const authHeaders = this.getAuthHeaders(authConfigId) const authHeaders = this.getAuthHeaders(authConfigId)
@ -352,7 +365,13 @@ module RestModule {
} }
let input: any = { method, headers: this.headers } let input: any = { method, headers: this.headers }
input = this.addBody(bodyType, requestBody, input, pagination, paginationValues) input = this.addBody(
bodyType,
requestBody,
input,
pagination,
paginationValues
)
this.startTimeMs = performance.now() this.startTimeMs = performance.now()
const url = this.getUrl(path, queryString, pagination, paginationValues) const url = this.getUrl(path, queryString, pagination, paginationValues)

View file

@ -38,7 +38,7 @@ module S3Module {
signatureVersion: { signatureVersion: {
type: "string", type: "string",
required: false, required: false,
default: "v4" default: "v4",
}, },
}, },
query: { query: {

View file

@ -47,6 +47,15 @@ module.exports = async (ctx, next) => {
(!ctx.user || !ctx.user.builder || !ctx.user.builder.global) (!ctx.user || !ctx.user.builder || !ctx.user.builder.global)
) { ) {
clearCookie(ctx, Cookies.CurrentApp) clearCookie(ctx, Cookies.CurrentApp)
// have to set the return url on the server side as client side is not available
setCookie(ctx, ctx.url, Cookies.RETURN_URL, {
// don't sign so the browser can easily read
sign: false,
// use the request domain to match how ui handles the return url cookie.
// it's important we don't use the shared domain here as the builder
// can't delete from it without awareness of the domain.
requestDomain: true,
})
return ctx.redirect("/") return ctx.redirect("/")
} }