appstage 0.2.21 → 0.2.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +10 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.mjs +10 -1
- package/index.ts +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -162,6 +162,15 @@ const files = (params) => {
|
|
|
162
162
|
};
|
|
163
163
|
};
|
|
164
164
|
|
|
165
|
+
const redirect = (params) => {
|
|
166
|
+
let { url, status = 302 } = typeof params === "string" ? { url: params } : params;
|
|
167
|
+
return (req, res) => {
|
|
168
|
+
let search = req.originalUrl.split("?")[1] ?? "";
|
|
169
|
+
if (search) search = `${url.includes("?") ? "&" : "?"}${search}`;
|
|
170
|
+
res.redirect(status, `${url}${search}`);
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
|
|
165
174
|
const unhandledError = () => async (err, req, res) => {
|
|
166
175
|
emitLog(req.app, "Unhandled error", {
|
|
167
176
|
level: "error",
|
|
@@ -690,6 +699,7 @@ exports.init = init;
|
|
|
690
699
|
exports.injectNonce = injectNonce;
|
|
691
700
|
exports.lang = lang;
|
|
692
701
|
exports.log = log;
|
|
702
|
+
exports.redirect = redirect;
|
|
693
703
|
exports.renderStatus = renderStatus;
|
|
694
704
|
exports.requestEvents = requestEvents;
|
|
695
705
|
exports.serializeState = serializeState;
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,12 @@ type FilesParams = {
|
|
|
32
32
|
*/
|
|
33
33
|
declare const files: Controller<string | FilesParams>;
|
|
34
34
|
|
|
35
|
+
type RedirectParams = {
|
|
36
|
+
url: string;
|
|
37
|
+
status?: number;
|
|
38
|
+
};
|
|
39
|
+
declare const redirect: Controller<string | RedirectParams>;
|
|
40
|
+
|
|
35
41
|
type ErrorController<T = void> = (params: T) => ErrorRequestHandler;
|
|
36
42
|
|
|
37
43
|
declare const unhandledError: ErrorController;
|
|
@@ -1123,4 +1129,4 @@ declare function servePipeableStream(req: Request, res: Response): ({
|
|
|
1123
1129
|
pipe
|
|
1124
1130
|
}: PipeableStream, error?: unknown) => Promise<void>;
|
|
1125
1131
|
|
|
1126
|
-
export { Controller, ErrorController, FilesParams, LangParams, LogEventPayload, LogLevel, LogOptions, Middleware, MiddlewareSet, RenderStatus, ReqCtx, TransformContent, build, cli, createApp, cspNonce, emitLog, files, getEffectiveLocale, getLocales, getStatusMessage, init, injectNonce, lang, log, renderStatus, requestEvents, serializeState, servePipeableStream, toLanguage, unhandledError, unhandledRoute };
|
|
1132
|
+
export { Controller, ErrorController, FilesParams, LangParams, LogEventPayload, LogLevel, LogOptions, Middleware, MiddlewareSet, RedirectParams, RenderStatus, ReqCtx, TransformContent, build, cli, createApp, cspNonce, emitLog, files, getEffectiveLocale, getLocales, getStatusMessage, init, injectNonce, lang, log, redirect, renderStatus, requestEvents, serializeState, servePipeableStream, toLanguage, unhandledError, unhandledRoute };
|
package/dist/index.mjs
CHANGED
|
@@ -136,6 +136,15 @@ const files = (params) => {
|
|
|
136
136
|
};
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
+
const redirect = (params) => {
|
|
140
|
+
let { url, status = 302 } = typeof params === "string" ? { url: params } : params;
|
|
141
|
+
return (req, res) => {
|
|
142
|
+
let search = req.originalUrl.split("?")[1] ?? "";
|
|
143
|
+
if (search) search = `${url.includes("?") ? "&" : "?"}${search}`;
|
|
144
|
+
res.redirect(status, `${url}${search}`);
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
|
|
139
148
|
const unhandledError = () => async (err, req, res) => {
|
|
140
149
|
emitLog(req.app, "Unhandled error", {
|
|
141
150
|
level: "error",
|
|
@@ -651,4 +660,4 @@ function servePipeableStream(req, res) {
|
|
|
651
660
|
};
|
|
652
661
|
}
|
|
653
662
|
|
|
654
|
-
export { build, cli, createApp, cspNonce, emitLog, files, getEffectiveLocale, getLocales, getStatusMessage, init, injectNonce, lang, log, renderStatus, requestEvents, serializeState, servePipeableStream, toLanguage, unhandledError, unhandledRoute };
|
|
663
|
+
export { build, cli, createApp, cspNonce, emitLog, files, getEffectiveLocale, getLocales, getStatusMessage, init, injectNonce, lang, log, redirect, renderStatus, requestEvents, serializeState, servePipeableStream, toLanguage, unhandledError, unhandledRoute };
|
package/index.ts
CHANGED