@webqit/webflo 0.20.9 → 0.20.11-next.0
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/package.json
CHANGED
|
@@ -140,18 +140,36 @@ export const response = {
|
|
|
140
140
|
return instance;
|
|
141
141
|
}
|
|
142
142
|
},
|
|
143
|
+
redirect: {
|
|
144
|
+
value: function (url, status = 302) {
|
|
145
|
+
if (typeof url !== 'string' && !(url instanceof URL)) {
|
|
146
|
+
throw new Error('Redirect URL must be a string or URL!');
|
|
147
|
+
}
|
|
148
|
+
if (typeof status !== 'number') {
|
|
149
|
+
throw new Error('Redirect code must be a number!');
|
|
150
|
+
}
|
|
151
|
+
return new Response(null, { status, headers: { Location: url } });
|
|
152
|
+
}
|
|
153
|
+
},
|
|
143
154
|
redirectWith: {
|
|
144
|
-
value: function (url,
|
|
145
|
-
if (typeof
|
|
146
|
-
throw new Error('Redirect
|
|
155
|
+
value: function (url, ...args) {
|
|
156
|
+
if (typeof url !== 'string' && !(url instanceof URL)) {
|
|
157
|
+
throw new Error('Redirect URL must be a string or URL!');
|
|
158
|
+
}
|
|
159
|
+
let status = 302;
|
|
160
|
+
if (!_isObject(args[0])) {
|
|
161
|
+
status = args.shift();
|
|
147
162
|
}
|
|
148
|
-
if (
|
|
149
|
-
throw new Error('
|
|
163
|
+
if (typeof status !== 'number') {
|
|
164
|
+
throw new Error('Redirect code must be a number!');
|
|
150
165
|
}
|
|
151
|
-
|
|
152
|
-
|
|
166
|
+
if (args.some((arg) => !_isObject(arg))) {
|
|
167
|
+
throw new Error('Redirect arguments must be objects!');
|
|
168
|
+
}
|
|
169
|
+
const responseInstance = new Response(null, { status, headers: { Location: url } });
|
|
170
|
+
if (args.length) {
|
|
153
171
|
const responseMeta = _wq(responseInstance, 'meta');
|
|
154
|
-
responseMeta.set('carry',
|
|
172
|
+
responseMeta.set('carry', args);
|
|
155
173
|
}
|
|
156
174
|
return responseInstance;
|
|
157
175
|
}
|
|
@@ -436,12 +454,5 @@ export function renderCookieObjToString(cookieObj) {
|
|
|
436
454
|
if (_attrName === 'MaxAge') { _attrName = 'Max-Age' };
|
|
437
455
|
attrsArr.push(cookieObj[attrName] === true ? _attrName : `${_attrName}=${cookieObj[attrName]}`);
|
|
438
456
|
}
|
|
439
|
-
return attrsArr.join(';');
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
// ----- shim
|
|
443
|
-
|
|
444
|
-
const importUrl = new URL(import.meta.url);
|
|
445
|
-
if (importUrl.searchParams.has('shim')) {
|
|
446
|
-
shim(importUrl.searchParams.get('shim')?.trim());
|
|
447
|
-
}
|
|
457
|
+
return attrsArr.join('; ');
|
|
458
|
+
}
|