|
| 1 | +import type { RequestEvent } from '@builder.io/qwik-city'; |
| 2 | + |
| 3 | +// Keep in sync with `public/_redirects` |
| 4 | + |
| 5 | +export const onGet = ({ url, redirect }: RequestEvent) => { |
| 6 | + const { pathname } = url; |
| 7 | + const tempRedirect = tempRedirects[pathname]; |
| 8 | + if (tempRedirect) { |
| 9 | + throw redirect(307, tempRedirect); |
| 10 | + } |
| 11 | + const redirectUrl = redirects[pathname]; |
| 12 | + if (redirectUrl) { |
| 13 | + throw redirect(308, redirectUrl); |
| 14 | + } |
| 15 | + const rewritePrefix = (path: string, replacement: string) => { |
| 16 | + if (pathname.startsWith(path)) { |
| 17 | + throw redirect(308, pathname.replace(path, replacement)); |
| 18 | + } |
| 19 | + }; |
| 20 | + rewritePrefix('/docs/components/', '/docs/core/'); |
| 21 | + rewritePrefix('/deployments/', '/docs/deployments/'); |
| 22 | + rewritePrefix('/integrations/', '/docs/integrations/'); |
| 23 | + rewritePrefix('/qwikcity/', '/docs/'); |
| 24 | +}; |
| 25 | + |
| 26 | +const tempRedirects: Record<string, string> = { |
| 27 | + '/chat': ' https://discord.gg/TsNCMd6uGW', |
| 28 | + '/chat/': ' https://discord.gg/TsNCMd6uGW', |
| 29 | + |
| 30 | + '/examples ': '/examples/introduction/hello-world/', |
| 31 | + '/examples/ ': '/examples/introduction/hello-world/', |
| 32 | + '/guide ': '/docs/', |
| 33 | + '/guide/ ': '/docs/', |
| 34 | + '/tutorial ': '/tutorial/welcome/overview/', |
| 35 | + '/tutorial/ ': '/tutorial/welcome/overview/', |
| 36 | + '/tutorials ': '/tutorial/welcome/overview/', |
| 37 | + '/tutorials/ ': '/tutorial/welcome/overview/', |
| 38 | +}; |
| 39 | + |
| 40 | +const redirects: Record<string, string> = { |
| 41 | + '/tutorial/hooks/use-client-effect/': '/tutorial/hooks/use-visible-task/', |
| 42 | + |
| 43 | + '/integrations/deployments/azure-swa/': '/deployments/azure-swa/', |
| 44 | + '/integrations/deployments/cloudflare-pages/': '/deployments/cloudflare-pages/', |
| 45 | + '/integrations/deployments/express/': '/deployments/express/', |
| 46 | + '/integrations/deployments/netlify-edge/': '/deployments/netlify-edge/', |
| 47 | + '/integrations/deployments/vercel-edge/': '/deployments/vercel-edge/', |
| 48 | + |
| 49 | + '/qwikcity/advanced/prefetching/': '/docs/advanced/modules-prefetching/', |
| 50 | + '/qwikcity/content/component/': '/docs/pages/', |
| 51 | + '/qwikcity/content/head/': '/docs/pages/', |
| 52 | + '/qwikcity/content/mdx/': '/docs/guides/mdx/', |
| 53 | + '/qwikcity/content/menu/': '/docs/advanced/menu/', |
| 54 | + '/qwikcity/data/endpoints/': '/docs/endpoints/', |
| 55 | + '/qwikcity/data/modify/': '/docs/endpoints/', |
| 56 | + '/qwikcity/data/overview/': '/docs/routing/', |
| 57 | + '/qwikcity/data/redirects/': '/docs/guides/redirects/', |
| 58 | + '/qwikcity/data/retrieve/': '/docs/routing/', |
| 59 | + '/qwikcity/directory-layout/': '/docs/project-structure/', |
| 60 | + '/qwikcity/layout/grouped/': '/docs/advanced/routing/', |
| 61 | + '/qwikcity/layout/named/': '/docs/advanced/routing/', |
| 62 | + '/qwikcity/layout/nested/': '/docs/advanced/routing/', |
| 63 | + '/qwikcity/layout/overview/': '/docs/layout/', |
| 64 | + '/qwikcity/loader/': '/docs/route-loader/', |
| 65 | + '/qwikcity/middleware/azure-swa/': '/deployments/azure-swa/', |
| 66 | + '/qwikcity/middleware/cloudflare-pages/': '/deployments/cloudflare-pages/', |
| 67 | + '/qwikcity/middleware/express/': '/deployments/node/', |
| 68 | + '/qwikcity/middleware/netlify-edge/': '/deployments/netlify-edge/', |
| 69 | + '/qwikcity/middleware/node/': '/deployments/node/', |
| 70 | + '/qwikcity/prefetching/overview/': '/docs/advanced/speculative-module-fetching/', |
| 71 | + '/qwikcity/prefetching/parallelizing-network-requests/': |
| 72 | + '/docs/advanced/speculative-module-fetching/', |
| 73 | + '/qwikcity/prefetching/request-response-cache/': '/docs/advanced/speculative-module-fetching/', |
| 74 | + '/qwikcity/prefetching/service-worker-prefetching/': |
| 75 | + '/docs/advanced/speculative-module-fetching/', |
| 76 | + '/qwikcity/routing/error-responses/': '/docs/advanced/routing/', |
| 77 | + '/qwikcity/routing/overview/': '/docs/routing/', |
| 78 | + '/qwikcity/routing/pathless/': '/docs/layout/grouped/', |
| 79 | + '/qwikcity/routing/route-parameters/': '/docs/routing/', |
| 80 | + '/qwikcity/static-assets/': '/docs/advanced/static-assets/', |
| 81 | + '/qwikcity/static-site-generation/dynamic-routes/': '/docs/guides/static-site-generation/', |
| 82 | + '/qwikcity/static-site-generation/overview/': '/docs/guides/static-site-generation/', |
| 83 | + '/qwikcity/static-site-generation/static-site-config/': '/docs/guides/static-site-generation/', |
| 84 | + |
| 85 | + '/docs/advanced/i18n/': '/docs/integrations/i18n/', |
| 86 | + '/docs/cheat/best-practices/': '/docs/guides/best-practices/', |
| 87 | + '/docs/cheat/qwik-react/': '/docs/integrations/react/', |
| 88 | + '/docs/cheat/serialization/': '/docs/guides/serialization/', |
| 89 | + '/docs/components/inline-components/': '/docs/core/overview/', |
| 90 | + '/docs/components/lifecycle/': '/docs/core/tasks/', |
| 91 | + '/docs/components/projection/': '/docs/core/slots/', |
| 92 | + '/docs/components/resource/': '/docs/core/state/', |
| 93 | + '/docs/cookbook/re-exporting-loaders/': '/docs/re-exporting-loaders/', |
| 94 | + '/docs/env-variables/': '/docs/guides/env-variables/', |
| 95 | + '/docs/overview': '/docs/', |
| 96 | + '/docs/overview/': '/docs/', |
| 97 | + '/docs/think-qwik/': '/docs/concepts/think-qwik/', |
| 98 | +}; |
0 commit comments