diff --git a/package.json b/package.json index 5b2b1376..7c230823 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "dayjs": "^1.11.10", "dompurify": "^3.0.6", "localforage": "^1.10.0", + "node-fetch": "^3.3.2", "nprogress": "^0.2.0", "pinia": "^2.1.7", "pinia-plugin-persistedstate": "^3.2.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0fcc3bac..065fae5b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -68,6 +68,9 @@ dependencies: localforage: specifier: ^1.10.0 version: 1.10.0 + node-fetch: + specifier: ^3.3.2 + version: 3.3.2 nprogress: specifier: ^0.2.0 version: 0.2.0 @@ -1292,6 +1295,11 @@ packages: /csstype@3.1.2: resolution: {integrity: sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==} + /data-uri-to-buffer@4.0.1: + resolution: {integrity: sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==} + engines: {node: '>= 12'} + dev: false + /dayjs@1.11.10: resolution: {integrity: sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ==} dev: false @@ -1493,6 +1501,14 @@ packages: resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==} dev: false + /fetch-blob@3.2.0: + resolution: {integrity: sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==} + engines: {node: ^12.20 || >= 14.13} + dependencies: + node-domexception: 1.0.0 + web-streams-polyfill: 3.2.1 + dev: false + /fill-range@7.0.1: resolution: {integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==} engines: {node: '>=8'} @@ -1515,6 +1531,13 @@ packages: - supports-color dev: true + /formdata-polyfill@4.0.10: + resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==} + engines: {node: '>=12.20.0'} + dependencies: + fetch-blob: 3.2.0 + dev: false + /forwarded@0.2.0: resolution: {integrity: sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==} engines: {node: '>= 0.6'} @@ -2316,6 +2339,20 @@ packages: engines: {node: '>= 0.6'} dev: true + /node-domexception@1.0.0: + resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==} + engines: {node: '>=10.5.0'} + dev: false + + /node-fetch@3.3.2: + resolution: {integrity: sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dependencies: + data-uri-to-buffer: 4.0.1 + fetch-blob: 3.2.0 + formdata-polyfill: 4.0.10 + dev: false + /normalize-path@3.0.0: resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==} engines: {node: '>=0.10.0'} @@ -3063,6 +3100,11 @@ packages: resolution: {integrity: sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==} dev: false + /web-streams-polyfill@3.2.1: + resolution: {integrity: sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==} + engines: {node: '>= 8'} + dev: false + /wrap-ansi@7.0.0: resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} engines: {node: '>=10'} diff --git a/src/entry-client.ts b/src/entry-client.ts index ce4b2133..e233f270 100644 --- a/src/entry-client.ts +++ b/src/entry-client.ts @@ -4,7 +4,7 @@ import { setupPinia } from './store' import i18n from '@/language/i18n' import '@/styles/index.scss' -const router = createKUNGalgameRouter('client') +const router = createKUNGalgameRouter() const pinia = setupPinia() const { app } = createApp() diff --git a/src/entry-server.ts b/src/entry-server.ts index 075fbdfb..8ee4c7bb 100644 --- a/src/entry-server.ts +++ b/src/entry-server.ts @@ -47,11 +47,11 @@ const renderPreloadLinks = ( export const render = async ( ctx: ParameterizedContext, manifest: Record -): Promise<[string, string, string, string]> => { +): Promise<[string, string, string]> => { const { app } = createApp() // router - const router = createKUNGalgameRouter('server') + const router = createKUNGalgameRouter() app.use(router) await router.push(ctx.path) await router.isReady() @@ -71,7 +71,5 @@ export const render = async ( const renderedLinks = renderPreloadLinks(renderCtx.modules, manifest) - const renderedTeleports = ctx.teleports - - return [renderedHtml, renderedPinia, renderedLinks, renderedTeleports] + return [renderedHtml, renderedPinia, renderedLinks] } diff --git a/src/router/index.ts b/src/router/index.ts index 532ca5a4..8330617d 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -3,12 +3,11 @@ import { createWebHistory, createRouter, createMemoryHistory } from 'vue-router' import { constantRoutes } from './router' import { asyncRoutes } from './router' -export const createKUNGalgameRouter = (type: 'client' | 'server'): Router => +export const createKUNGalgameRouter = (): Router => createRouter({ - history: - type === 'server' - ? createMemoryHistory(import.meta.env.BASE_URL) - : createWebHistory(import.meta.env.BASE_URL), + history: import.meta.env.SSR + ? createMemoryHistory(import.meta.env.BASE_URL) + : createWebHistory(import.meta.env.BASE_URL), routes: [...constantRoutes, ...asyncRoutes] as RouteRecordRaw[], diff --git a/src/utils/request.ts b/src/utils/request.ts index 8a0c1a6d..e67e41a2 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -7,7 +7,7 @@ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' const successResponseArray = [200, 201, 202, 204, 205, 206] -export type FetchOptions = { +export type FetchOptions = RequestInit & { method: HttpMethod credentials: 'include' headers?: Record