nuxt-outfit 1.3.0 → 1.4.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/dist/module.json
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { readonly } from "vue";
|
|
2
|
+
import { useRequestEvent } from "#imports";
|
|
3
|
+
import { setResponseHeaders } from "h3";
|
|
4
|
+
import { parse, splitCookiesString as split } from "set-cookie-parser";
|
|
5
|
+
import { serialize } from "cookie";
|
|
6
|
+
export const useGoodResponse = () => {
|
|
7
|
+
const event = useRequestEvent();
|
|
8
|
+
const goodCodes = readonly([200, 201, 202, 203, 204, 205, 206, 207, 208, 226]);
|
|
9
|
+
const parseCookie = (cookies) => {
|
|
10
|
+
return parse(split(cookies)).map((cookie) => serialize(cookie.name, cookie.value, cookie));
|
|
11
|
+
};
|
|
12
|
+
const setCookieFromResponse = ({ status, headers }) => {
|
|
13
|
+
if (goodCodes.includes(status)) {
|
|
14
|
+
setResponseHeaders(event, { "Set-Cookie": parseCookie(headers.get("set-cookie")) });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
goodCodes,
|
|
19
|
+
setCookieFromResponse
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
export declare const useSpaHeaders: (additionalHeaders?: {}) => {
|
|
2
2
|
headers: any;
|
|
3
|
-
onResponse({ response }: {
|
|
4
|
-
response: any;
|
|
5
|
-
}): Promise<void>;
|
|
6
3
|
} | {
|
|
7
4
|
headers: {};
|
|
8
|
-
onRequest({
|
|
9
|
-
request: any;
|
|
5
|
+
onRequest({ options }: {
|
|
10
6
|
options: any;
|
|
11
7
|
}): Promise<void>;
|
|
12
8
|
};
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { useRuntimeConfig, useRequestEvent, useRequestHeaders, useEcho } from "#imports";
|
|
2
|
-
import { appendHeader } from "h3";
|
|
3
|
-
import { parse, splitCookiesString as split } from "set-cookie-parser";
|
|
4
|
-
import { serialize } from "cookie";
|
|
5
2
|
export const useSpaHeaders = (additionalHeaders = {}) => {
|
|
6
3
|
if (process.client) {
|
|
7
4
|
const { getSocketId } = useEcho();
|
|
8
5
|
return {
|
|
9
6
|
headers: additionalHeaders,
|
|
10
|
-
async onRequest({
|
|
7
|
+
async onRequest({ options }) {
|
|
11
8
|
if (getSocketId() !== void 0) {
|
|
12
9
|
options.headers["X-Socket-ID"] = getSocketId();
|
|
13
10
|
}
|
|
@@ -17,21 +14,11 @@ export const useSpaHeaders = (additionalHeaders = {}) => {
|
|
|
17
14
|
const serverUrl = useRuntimeConfig().outfit.serverUrl;
|
|
18
15
|
const event = useRequestEvent();
|
|
19
16
|
const headers = useRequestHeaders(["cookie", "referer", "host"]);
|
|
20
|
-
const goodResponses = [200, 201, 202, 203, 204, 205, 206, 207, 208, 226];
|
|
21
17
|
headers.referer = `${headers.host}${event.node.req.originalUrl}`;
|
|
22
|
-
const parseCookie = (cookies) => {
|
|
23
|
-
return parse(split(cookies)).map((cookie) => serialize(cookie.name, cookie.value, cookie));
|
|
24
|
-
};
|
|
25
18
|
const serverOptions = {
|
|
26
19
|
headers: {
|
|
27
20
|
...additionalHeaders,
|
|
28
21
|
...headers
|
|
29
|
-
},
|
|
30
|
-
async onResponse({ response }) {
|
|
31
|
-
const { status, headers: headers2 } = response;
|
|
32
|
-
if (goodResponses.includes(status)) {
|
|
33
|
-
appendHeader(event, "Set-Cookie", parseCookie(headers2.get("set-cookie")));
|
|
34
|
-
}
|
|
35
22
|
}
|
|
36
23
|
};
|
|
37
24
|
if (serverUrl) {
|