sourcegraph/client/web/dev/server/devProxyServer.ts
Quinn Slack 86180de04a
use vite for web builds (#58228)
* remove little-used `web-standalone-http-prod`

This let you run a local web app built in production mode against a remote Sourcegraph endpoint. You can still run a local web app built in *dev* mode.

* add `sg test bazel-backend-integration`

* fix DeveloperDialog positioning

It was taking up 100% width and was translated -50% so the left half of it was off-viewport.

* use vite for web builds

[Vite](https://vitejs.dev/) is a fast web bundler. With Vite, a local dev server is available as fast as with esbuild, and incremental builds are (1) hot (no page reload needed) and (2) much faster (<500ms).

* fix "manifestPlugin.d.ts" was not created

* sg lint

* remove little-used `web-standalone-http-prod`

This let you run a local web app built in production mode against a remote Sourcegraph endpoint. You can still run a local web app built in *dev* mode.

* add `sg test bazel-backend-integration`

* fix DeveloperDialog positioning

It was taking up 100% width and was translated -50% so the left half of it was off-viewport.

* use vite for web builds

[Vite](https://vitejs.dev/) is a fast web bundler. With Vite, a local dev server is available as fast as with esbuild, and incremental builds are (1) hot (no page reload needed) and (2) much faster (<500ms).

* fix "manifestPlugin.d.ts" was not created

* sg lint

* small lint fix

* added events shim to client/web/BUILD.bazel

* updated via bazel configure

* added in side-effectful import for EventEmitter

* added in side-effectful import for EventEmitter

* ran bazel configure

* re-run bazel configure

* pnpm dedupe

---------

Co-authored-by: William Bezuidenhout <william.bezuidenhout@sourcegraph.com>
Co-authored-by: jamesmcnamara <jamesscottmcnamara@gmail.com>
Co-authored-by: Jean-Hadrien Chabran <jh@chabran.fr>
2023-12-19 19:16:51 -08:00

57 lines
1.8 KiB
TypeScript

import express from 'express'
import { createProxyMiddleware } from 'http-proxy-middleware'
import signale from 'signale'
import { ENVIRONMENT_CONFIG, HTTPS_WEB_SERVER_URL } from '../utils/environment-config'
import { getIndexHTML, getWebBuildManifest } from '../utils/get-index-html'
import { printSuccessBanner } from '../utils/success-banner'
import { getAPIProxySettings } from './apiProxySettings'
const { SOURCEGRAPH_API_URL, SOURCEGRAPH_HTTP_PORT } = ENVIRONMENT_CONFIG
interface DevelopmentServerInit {
apiURL: string
listenAddress?: { host: string; port: number }
}
async function startDevProxyServer({
apiURL,
listenAddress = { host: '127.0.0.1', port: SOURCEGRAPH_HTTP_PORT },
}: DevelopmentServerInit): Promise<void> {
const { proxyRoutes, ...proxyMiddlewareOptions } = getAPIProxySettings({
apiURL,
getLocalIndexHTML(jsContextScript) {
return getIndexHTML({ manifest: getWebBuildManifest(), jsContextScript })
},
})
const proxyServer = express()
proxyServer.use(createProxyMiddleware(proxyRoutes, proxyMiddlewareOptions))
return new Promise<void>((_resolve, reject) => {
proxyServer
.listen(listenAddress)
.once('listening', () => {
printSuccessBanner(['✱ Sourcegraph is really ready now!', `Click here: ${HTTPS_WEB_SERVER_URL}`])
})
.once('error', error => reject(error))
})
}
if (require.main === module) {
signale.start('Starting dev server.', ENVIRONMENT_CONFIG)
if (!SOURCEGRAPH_API_URL) {
throw new Error(
'development.server.ts only supports *web-standalone* usage (must set SOURCEGRAPH_API_URL env var)'
)
}
startDevProxyServer({
apiURL: SOURCEGRAPH_API_URL,
}).catch(error => {
signale.error(error)
process.exit(1)
})
}