|
1 | 1 | import { withSentryConfig } from "@sentry/nextjs"; |
2 | 2 | import type { NextConfig } from "next"; |
3 | | - |
| 3 | +import list from "./list.json"; |
4 | 4 | const nextConfig: NextConfig = { |
5 | 5 | output: "standalone", |
6 | 6 | basePath: "", |
@@ -31,36 +31,69 @@ const nextConfig: NextConfig = { |
31 | 31 |
|
32 | 32 | return config; |
33 | 33 | }, |
34 | | -}; |
| 34 | + async redirects() { |
| 35 | + const redirectList = []; |
35 | 36 |
|
36 | | -export default withSentryConfig(nextConfig, { |
37 | | - // For all available options, see: |
38 | | - // https://www.npmjs.com/package/@sentry/webpack-plugin#options |
| 37 | + const normalizeSlug = (text: string, preserveDots = false) => { |
| 38 | + return text |
| 39 | + .toLowerCase() |
| 40 | + .replace(preserveDots ? /[^a-z0-9.]+/g : /[^a-z0-9]+/g, "-") |
| 41 | + .replace(/-+/g, "-") |
| 42 | + .replace(/^-+|-+$/g, ""); |
| 43 | + }; |
39 | 44 |
|
40 | | - org: "apisguru", |
41 | | - project: "apis-guru", |
| 45 | + const normalizeServiceSlug = (service: string) => { |
| 46 | + return service |
| 47 | + .toLowerCase() |
| 48 | + .replace(/[\(\)]/g, "") |
| 49 | + .replace(/[^a-z0-9]+/g, "-") |
| 50 | + .replace(/-+/g, "-") |
| 51 | + .replace(/^-+|-+$/g, ""); |
| 52 | + }; |
42 | 53 |
|
43 | | - // Only print logs for uploading source maps in CI |
44 | | - silent: !process.env.CI, |
| 54 | + for (const key in list) { |
| 55 | + if (!Object.prototype.hasOwnProperty.call(list, key)) continue; |
45 | 56 |
|
46 | | - // For all available options, see: |
47 | | - // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/ |
| 57 | + const [provider, service] = key.split(":"); |
| 58 | + if (!provider) { |
| 59 | + console.warn(`Invalid key format: ${key}`); |
| 60 | + continue; |
| 61 | + } |
48 | 62 |
|
49 | | - // Upload a larger set of source maps for prettier stack traces (increases build time) |
50 | | - widenClientFileUpload: true, |
| 63 | + const legacyFullSlug = normalizeSlug(key); |
| 64 | + const currentProviderSlug = normalizeSlug(provider, true); |
| 65 | + const legacyProviderSlug = normalizeSlug(provider.replace(/\./g, "-")); |
51 | 66 |
|
52 | | - // Uncomment to route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers. |
53 | | - // This can increase your server load as well as your hosting bill. |
54 | | - // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client- |
55 | | - // side errors will fail. |
56 | | - // tunnelRoute: "/monitoring", |
| 67 | + const destination = service |
| 68 | + ? `/apis/${encodeURIComponent(currentProviderSlug)}/${encodeURIComponent(normalizeServiceSlug(service))}` |
| 69 | + : `/apis/${encodeURIComponent(currentProviderSlug)}`; |
57 | 70 |
|
58 | | - // Automatically tree-shake Sentry logger statements to reduce bundle size |
59 | | - disableLogger: true, |
| 71 | + if (legacyFullSlug !== currentProviderSlug) { |
| 72 | + redirectList.push({ |
| 73 | + source: `/apis/${encodeURIComponent(legacyFullSlug)}`, |
| 74 | + destination, |
| 75 | + permanent: true, |
| 76 | + }); |
| 77 | + } |
| 78 | + |
| 79 | + if (legacyProviderSlug !== currentProviderSlug) { |
| 80 | + redirectList.push({ |
| 81 | + source: `/apis/${encodeURIComponent(legacyProviderSlug)}`, |
| 82 | + destination: `/apis/${encodeURIComponent(currentProviderSlug)}`, |
| 83 | + permanent: true, |
| 84 | + }); |
| 85 | + } |
| 86 | + } |
60 | 87 |
|
61 | | - // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.) |
62 | | - // See the following for more information: |
63 | | - // https://docs.sentry.io/product/crons/ |
64 | | - // https://vercel.com/docs/cron-jobs |
| 88 | + return redirectList; |
| 89 | + }, |
| 90 | +}; |
| 91 | + |
| 92 | +export default withSentryConfig(nextConfig, { |
| 93 | + org: "apisguru", |
| 94 | + project: "apis-guru", |
| 95 | + silent: !process.env.CI, |
| 96 | + widenClientFileUpload: true, |
| 97 | + disableLogger: true, |
65 | 98 | automaticVercelMonitors: true, |
66 | 99 | }); |
0 commit comments