This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmiddleware.ts
152 lines (149 loc) · 8.87 KB
/
middleware.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import { NextRequest, NextResponse } from 'next/server'
// this will redirect the domain landing page to the following page component
const SUBDOMAIN_LANDING_PAGES = {
docs: '/docs',
observability: '/blog/frontend-observability',
monitor: '/blog/frontend-observability',
nextjs: '/blog/feature-nextjs-integration',
nodejs: '/blog/feature-nodejs-integration',
errors: '/blog/new-error-management-ui',
}
export const DOCS_REDIRECTS = {
'amplitude-integration': '/docs/general/integrations/amplitude-integration',
'api/changelog': '/changelogs',
'api/haddsessionfeedback': '/docs/sdk/client#Hadd-session-feedback',
'api/hconsumeerror': '/docs/sdk/nodejs#Hconsume-error',
'api/hgetsessiondetails': '/docs/sdk/client#Hget-session-details',
'api/hgetsessionurl': '/docs/sdk/client#Hget-session-url',
'api/hidentify': '/docs/sdk/client#Hidentify',
'api/highlight': '/docs/sdk/nextjs#Highlight',
'api/hinit': '/docs/sdk/nodejs#Hinit',
'api/hisinitialized': '/docs/sdk/nodejs#His-initialized',
'api/hmetrics': '/docs/sdk/client#Hmetrics',
'api/hparseheaders': '/docs/sdk/nodejs#Hparse-headers',
'api/hrecordmetric': '/docs/sdk/nodejs#Hrecord-metric',
'api/hstart': '/docs/sdk/client#Hstart',
'api/hstop': '/docs/sdk/client#Hstop',
'api/htogglesessionfeedbackmodal': '/docs/sdk/client#Htoggle-session-feedback-modal',
'api/htrack': '/docs/sdk/client#Htrack',
'api/ljQK-hconsumeerror': '/docs/sdk/client#Hconsume-error',
'api/metrics': '/docs/sdk/client#Hmetrics',
'api/networkrecordingoptions': '/docs/sdk/client#Hinit',
'api/nodejs/h-init': '/docs/sdk/nodejs#Hinit',
'api/withhighlightconfig': '/docs/sdk/nextjs#withHighlightConfig',
'backend-sdk': '/docs/getting-started/4_backend-sdk',
'clearbit-integration': '/docs/integrations/clearbit-integration',
'client-sdk': '/docs/getting-started/client-sdk',
'console-messages': '/docs/session-replay/console-messages',
'content-security-policy': '/docs/tips/content-security-policy',
'electron-integration': '/docs/integrations/electron-integration',
'error-monitoring/sourcemaps': '/docs/general/product-features/error-monitoring/sourcemaps',
'express-backend': '/docs/getting-started/4_backend-sdk/nextjs',
'front-plugin': '/docs/integrations/front-plugin',
'frontend-observability': '/docs/getting-started/overview#For-your-Frontend',
'general/getting-started/client-sdk/nextjs': '/docs/getting-started/client-sdk/nextjs',
'general/product-features/frontend-observability': '/docs/getting-started/overview#For-your-Frontend',
'general/product-features/session-replay/canvas': '/docs/getting-started/client-sdk/replay-configuration/canvas',
'go-backend': '/docs/getting-started/4_backend-sdk/go',
'grouping-errors': '/docs/error-monitoring/grouping-errors',
'html-iframe-recording': '/docs/session-replay/html-iframe-recording',
'identifying-users': '/docs/session-replay/identifying-sessions',
'integrations/amplitude-integration': '/docs/general/integrations/amplitude-integration',
'integrations/mixpanel-integration': '/docs/general/integrations/mixpanel-integration',
'integrations/reactjs-integration': '/docs/getting-started/client-sdk/replay-configuration/react-error-boundary',
'integrations/sentry-integration': '/docs/general/product-features/error-monitoring/overview',
'intercom-integration': '/docs/integrations/intercom-integration',
'keyboard-shortcuts': '/docs/product-features/keyboard-shortcuts',
'linear-integration': '/docs/integrations/linear-integration',
'live-mode': '/docs/session-replay/live-mode',
'local-development': '/docs/tips/local-development',
'mixpanel-integration': '/docs/general/integrations/mixpanel-integration',
'monkey-patches': '/docs/tips/monkey-patches',
'network-devtools': '/docs/session-replay/network-devtools',
'nextjs-backend': '/docs/getting-started/4_backend-sdk/express',
'nextjs-sdk': '/docs/getting-started/4_backend-sdk/nextjs',
'nodejs-backend': '/docs/getting-started/4_backend-sdk/nodejs',
'performance-data': '/docs/product-features/performance-data',
'performance-impact': '/docs/tips/performance-impact',
'product-features/canvas': '/docs/general/product-features/session-replay/canvas',
'product-features/console-messages': '/docs/general/product-features/session-replay/console-messages',
'product-features/cross-origin-iframes': '/docs/general/product-features/session-replay/cross-origin-iframes',
'product-features/frontend-observability': '/docs/general/product-features/session-replay/overview',
'product-features/html-iframe-recording': '/docs/general/product-features/session-replay/html-iframe-recording',
'product-features/live-mode': '/docs/general/product-features/session-replay/live-mode',
'product-features/session-search': '/docs/general/product-features/session-replay/session-search',
'product-features/user-feedback': '/docs/general/product-features/session-replay/overview',
'product-features/versioning-sessions': '/docs/general/product-features/session-replay/versioning-sessions',
'product-features/web-vitals': '/docs/general/tips/performance-impact',
'proxying-highlight': '/docs/getting-started/client-sdk/replay-configuration/proxying-highlight',
'rage-clicks': '/docs/session-replay/rage-clicks',
'reactjs-integration': '/docs/getting-started/client-sdk/replay-configuration/react-error-boundary',
'recording-network-requests-and-responses': '/docs/session-replay/recording-network-requests-and-responses',
'segment-integration': '/docs/integrations/segment-integration',
'sentry-integration': '/docs/integrations/sentry-integration',
'session-replay/identifying-sessions': '/docs/general/product-features/session-replay/identifying-sessions',
'session-replay/privacy': '/docs/general/product-features/session-replay/privacy',
'session-replay/rage-clicks': '/docs/general/product-features/session-replay/rage-clicks',
'session-replay/recording-network-requests-and-responses':
'/docs/general/product-features/session-replay/recording-network-requests-and-responses',
'session-replay/tracking-events': '/docs/general/product-features/session-replay/tracking-events',
'session-search': '/docs/product-features/session-search',
'session-search-deep-linking': '/docs/tips/sessions-search-deep-linking',
'session-sharing': '/docs/session-replay/session-sharing',
'session-shortcut': '/docs/session-replay/session-shortcut',
'slack-integration': '/docs/integrations/slack-integration',
'team-management': '/docs/product-features/team-management',
'tips/proxying-highlight': '/docs/getting-started/client-sdk/replay-configuration/proxying-highlight',
'tracking-events': '/docs/session-replay/tracking-events',
'upgrading-highlight': '/docs/tips/upgrading-highlight',
'user-feedback': '/docs/product-features/user-feedback',
'vercel-integration': '/docs/integrations/vercel-integration',
'versioning-errors': '/docs/error-monitoring/versioning-errors',
'versioning-sessions': '/docs/session-replay/versioning-sessions',
'web-vitals': '/docs/product-features/web-vitals',
alerts: '/docs/product-features/alerts',
analytics: '/docs/product-features/analytics',
angular: '/docs/getting-started/client-sdk/angular',
api: '/docs/sdk/client#Hinit',
canvas: '/docs/getting-started/client-sdk/replay-configuration/canvas',
comments: '/docs/product-features/comments',
environments: '/docs/product-features/environments',
gatsbyjs: '/docs/getting-started/client-sdk/gatsbyjs',
html: '/docs/getting-started/client-sdk/html',
metrics: '/docs/getting-started/fullstack-frameworks/next-js/metrics-overview',
nextjs: '/docs/getting-started/client-sdk/nextjs',
other: '/docs/getting-started/client-sdk/other',
privacy: '/docs/session-replay/privacy',
segments: '/docs/product-features/segments',
shopify: '/docs/getting-started/client-sdk/shopify',
sourcemaps: '/docs/error-monitoring/sourcemaps',
squarespace: '/docs/getting-started/client-sdk/squarespace',
sveltekit: '/docs/getting-started/client-sdk/sveltekit',
troubleshooting: '/docs/tips/troubleshooting',
vuejs: '/docs/getting-started/client-sdk/vuejs',
webflow: '/docs/getting-started/client-sdk/webflow',
webgl: '/docs/product-features/webgl',
wordpress: '/docs/getting-started/client-sdk/wordpress',
}
export default function middleware(req: NextRequest) {
const { pathname } = req.nextUrl
const hostname = req.headers.get('host')
for (const [k, v] of Object.entries(SUBDOMAIN_LANDING_PAGES)) {
if (hostname?.startsWith(`${k}.`)) {
if (pathname === '/') {
let url = req.nextUrl.origin || 'https://highlight.io/'
url = url.replace(/\/+$/, '')
return NextResponse.rewrite(`${url}${v}`)
}
}
}
if (pathname.startsWith('/docs/')) {
for (const [k, v] of Object.entries(DOCS_REDIRECTS)) {
if (pathname === `/docs/${k}`) {
let url = req.nextUrl.origin || 'https://highlight.io/'
url = url.replace(/\/+$/, '')
return NextResponse.redirect(`${url}${v}`, { status: 302 })
}
}
}
}