Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 02fb199

Browse files
authored
chore(svelte): Add manual entries for repo sub pages to development proxy (#64313)
I noticed that non-svelte repo subpages haven't been redirected to the React app in local development (it works as expected in production). That's because the proxy doesn't know about them since they are not part of `knownRoutes`. We could update the server code to include those routes as well but that seems heavey handed just to make local development work. I think in this case it's fine to have manual entries for the handful of repo subpages that have not been migrated to Svelte yet. ## Test plan Manual testing.
1 parent b6a25c8 commit 02fb199

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

client/web-sveltekit/dev/vite-sg-proxy.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,20 @@ export function sgProxy(options: Options): Plugin {
3333
const contextPlaceholder = '// ---window.context---'
3434

3535
// Additional endpoints that should be proxied to the real Sourcegraph instance.
36-
// These are not part of the known routes, but are required for the SvelteKit app to work.
37-
const additionalEndpoints = ['/.api/', '/.assets/', '/.auth/']
36+
const additionalEndpoints = [
37+
// These are not part of the known routes list, but are required for the SvelteKit app to work
38+
// in development mode.
39+
'^/.api/',
40+
'^/.assets/',
41+
'^/.auth/',
42+
// Repo sub pages are also not part of the known routes list. They are listed here so that we
43+
// proxy them to the real Sourcegraph instance, for consistency with the production setup.
44+
'/-/raw/',
45+
'/-/batch-changes/?',
46+
'/-/settings/?',
47+
'/-/code-graph/?',
48+
'/-/own/?',
49+
]
3850

3951
// Routes known by the server that need to (potentially) be proxied to the real Sourcegraph instance.
4052
let knownServerRoutes: string[] = []
@@ -91,6 +103,7 @@ export function sgProxy(options: Options): Plugin {
91103
// from the JS context object. This is used to determine which requests should be proxied to the real Sourcegraph
92104
// instance.
93105
try {
106+
logger.info(`Fetching JS context from ${options.target}`, { timestamp: true })
94107
// The /sign-in endpoint is always available on dotcom and enterprise instances.
95108
context = await fetch(`${options.target}/sign-in`)
96109
.then(response => response.text())
@@ -125,7 +138,7 @@ export function sgProxy(options: Options): Plugin {
125138

126139
const proxyConfig: Record<string, ProxyOptions> = {
127140
// Proxy requests to specific endpoints to a real Sourcegraph instance.
128-
[`^(${additionalEndpoints.join('|')})`]: baseOptions,
141+
[`${additionalEndpoints.join('|')}`]: baseOptions,
129142
}
130143

131144
const dynamicOptions: ProxyOptions = {

0 commit comments

Comments
 (0)