Update pages server function(s)
This commit is contained in:
parent
35f7a6fc85
commit
e0c2ab5872
@ -3,8 +3,8 @@ import { log } from "../../../utils/log";
|
|||||||
import writeCache from "../../cache/write-cache";
|
import writeCache from "../../cache/write-cache";
|
||||||
export default async function generateWebPageGetCachePage({ module, routeParams, serverRes, root_module, html, }) {
|
export default async function generateWebPageGetCachePage({ module, routeParams, serverRes, root_module, html, }) {
|
||||||
const config = _.merge(root_module?.config, module?.config);
|
const config = _.merge(root_module?.config, module?.config);
|
||||||
const cache_page = config?.cachePage || serverRes?.cachePage || false;
|
const cache_page = config?.cachePage || serverRes?.cache_page || false;
|
||||||
const expiry_seconds = config?.cacheExpiry || serverRes?.cacheExpiry;
|
const expiry_seconds = config?.cacheExpiry || serverRes?.cache_expiry;
|
||||||
if (cache_page && routeParams?.url) {
|
if (cache_page && routeParams?.url) {
|
||||||
try {
|
try {
|
||||||
const is_cache = typeof cache_page == "boolean"
|
const is_cache = typeof cache_page == "boolean"
|
||||||
|
|||||||
@ -23,10 +23,10 @@ export default async function generateWebPageResponseFromComponentReturn({ compo
|
|||||||
: serverRes.redirect.status_code || 302);
|
: serverRes.redirect.status_code || 302);
|
||||||
}
|
}
|
||||||
const res_opts = {
|
const res_opts = {
|
||||||
...serverRes?.responseOptions,
|
...serverRes?.response_options,
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "text/html",
|
"Content-Type": "text/html",
|
||||||
...serverRes?.responseOptions?.headers,
|
...serverRes?.response_options?.headers,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if (is_dev) {
|
if (is_dev) {
|
||||||
@ -47,8 +47,11 @@ export default async function generateWebPageResponseFromComponentReturn({ compo
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const res = new Response(html, res_opts);
|
const res = new Response(html, res_opts);
|
||||||
if (routeParams?.resTransform) {
|
if (routeParams?.res_transform) {
|
||||||
return await routeParams.resTransform(res);
|
return await routeParams.res_transform(res);
|
||||||
|
}
|
||||||
|
if (serverRes?.res_transform) {
|
||||||
|
return await serverRes.res_transform(res);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,7 @@ export default async function grabPageErrorComponent({ error, routeParams, is404
|
|||||||
? BUNX_ROOT_404_PRESET_COMPONENT
|
? BUNX_ROOT_404_PRESET_COMPONENT
|
||||||
: BUNX_ROOT_500_PRESET_COMPONENT;
|
: BUNX_ROOT_500_PRESET_COMPONENT;
|
||||||
const default_server_res = {
|
const default_server_res = {
|
||||||
responseOptions: {
|
response_options: {
|
||||||
status: is404 ? 404 : 500,
|
status: is404 ? 404 : 500,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
9
dist/types/index.d.ts
vendored
9
dist/types/index.d.ts
vendored
@ -70,7 +70,7 @@ export type BunxRouteParams = {
|
|||||||
/**
|
/**
|
||||||
* Intercept and Transform the response object
|
* Intercept and Transform the response object
|
||||||
*/
|
*/
|
||||||
resTransform?: (res: Response) => Promise<Response> | Response;
|
res_transform?: (res: Response) => Promise<Response> | Response;
|
||||||
server?: Server<any>;
|
server?: Server<any>;
|
||||||
};
|
};
|
||||||
export interface PostInsertReturn {
|
export interface PostInsertReturn {
|
||||||
@ -207,17 +207,18 @@ export type BunextPageModuleServerReturn<T extends {
|
|||||||
props?: T;
|
props?: T;
|
||||||
query?: Q;
|
query?: Q;
|
||||||
redirect?: BunextPageModuleServerRedirect;
|
redirect?: BunextPageModuleServerRedirect;
|
||||||
responseOptions?: ResponseInit;
|
response_options?: ResponseInit;
|
||||||
/**
|
/**
|
||||||
* Whether to cache the current page
|
* Whether to cache the current page
|
||||||
*/
|
*/
|
||||||
cachePage?: BunextCachePageType;
|
cache_page?: BunextCachePageType;
|
||||||
/**
|
/**
|
||||||
* Expiry time of the cache in seconds
|
* Expiry time of the cache in seconds
|
||||||
*/
|
*/
|
||||||
cacheExpiry?: number;
|
cache_expiry?: number;
|
||||||
url?: BunextPageModuleServerReturnURLObject;
|
url?: BunextPageModuleServerReturnURLObject;
|
||||||
error?: string;
|
error?: string;
|
||||||
|
res_transform?: (res: Response) => Promise<Response> | Response;
|
||||||
};
|
};
|
||||||
export type BunextCachePageType = boolean | ((params: {
|
export type BunextCachePageType = boolean | ((params: {
|
||||||
ctx: Omit<BunxRouteParams, "body">;
|
ctx: Omit<BunxRouteParams, "body">;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/bunext",
|
"name": "@moduletrace/bunext",
|
||||||
"version": "1.0.73",
|
"version": "1.0.74",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"module": "index.ts",
|
"module": "index.ts",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@ -24,8 +24,8 @@ export default async function generateWebPageGetCachePage({
|
|||||||
}: Params) {
|
}: Params) {
|
||||||
const config = _.merge(root_module?.config, module?.config);
|
const config = _.merge(root_module?.config, module?.config);
|
||||||
|
|
||||||
const cache_page = config?.cachePage || serverRes?.cachePage || false;
|
const cache_page = config?.cachePage || serverRes?.cache_page || false;
|
||||||
const expiry_seconds = config?.cacheExpiry || serverRes?.cacheExpiry;
|
const expiry_seconds = config?.cacheExpiry || serverRes?.cache_expiry;
|
||||||
|
|
||||||
if (cache_page && routeParams?.url) {
|
if (cache_page && routeParams?.url) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -40,10 +40,10 @@ export default async function generateWebPageResponseFromComponentReturn({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const res_opts: ResponseInit = {
|
const res_opts: ResponseInit = {
|
||||||
...serverRes?.responseOptions,
|
...serverRes?.response_options,
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "text/html",
|
"Content-Type": "text/html",
|
||||||
...serverRes?.responseOptions?.headers,
|
...serverRes?.response_options?.headers,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -68,8 +68,12 @@ export default async function generateWebPageResponseFromComponentReturn({
|
|||||||
|
|
||||||
const res = new Response(html, res_opts);
|
const res = new Response(html, res_opts);
|
||||||
|
|
||||||
if (routeParams?.resTransform) {
|
if (routeParams?.res_transform) {
|
||||||
return await routeParams.resTransform(res);
|
return await routeParams.res_transform(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (serverRes?.res_transform) {
|
||||||
|
return await serverRes.res_transform(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@ -32,7 +32,7 @@ export default async function grabPageErrorComponent({
|
|||||||
: BUNX_ROOT_500_PRESET_COMPONENT;
|
: BUNX_ROOT_500_PRESET_COMPONENT;
|
||||||
|
|
||||||
const default_server_res = {
|
const default_server_res = {
|
||||||
responseOptions: {
|
response_options: {
|
||||||
status: is404 ? 404 : 500,
|
status: is404 ? 404 : 500,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -90,7 +90,7 @@ export type BunxRouteParams = {
|
|||||||
/**
|
/**
|
||||||
* Intercept and Transform the response object
|
* Intercept and Transform the response object
|
||||||
*/
|
*/
|
||||||
resTransform?: (res: Response) => Promise<Response> | Response;
|
res_transform?: (res: Response) => Promise<Response> | Response;
|
||||||
server?: Server<any>;
|
server?: Server<any>;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -238,17 +238,18 @@ export type BunextPageModuleServerReturn<
|
|||||||
props?: T;
|
props?: T;
|
||||||
query?: Q;
|
query?: Q;
|
||||||
redirect?: BunextPageModuleServerRedirect;
|
redirect?: BunextPageModuleServerRedirect;
|
||||||
responseOptions?: ResponseInit;
|
response_options?: ResponseInit;
|
||||||
/**
|
/**
|
||||||
* Whether to cache the current page
|
* Whether to cache the current page
|
||||||
*/
|
*/
|
||||||
cachePage?: BunextCachePageType;
|
cache_page?: BunextCachePageType;
|
||||||
/**
|
/**
|
||||||
* Expiry time of the cache in seconds
|
* Expiry time of the cache in seconds
|
||||||
*/
|
*/
|
||||||
cacheExpiry?: number;
|
cache_expiry?: number;
|
||||||
url?: BunextPageModuleServerReturnURLObject;
|
url?: BunextPageModuleServerReturnURLObject;
|
||||||
error?: string;
|
error?: string;
|
||||||
|
res_transform?: (res: Response) => Promise<Response> | Response;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type BunextCachePageType =
|
export type BunextCachePageType =
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user