mirror of
https://github.com/enso-org/enso.git
synced 2024-12-22 15:21:43 +03:00
866501fa81
Sets production redirect URL to `localhost:8080`. This *would* break `cloud.enso.org`, but I believe there are no plans to upload the new dashboard to `cloud.enso.org` in the near future, so this should be acceptable for the time being # Important Notes None
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
/** @file File watch and compile service. */
|
|
import * as path from 'node:path'
|
|
import * as url from 'node:url'
|
|
|
|
import * as esbuild from 'esbuild'
|
|
import chalk from 'chalk'
|
|
|
|
import * as bundler from './esbuild-config'
|
|
|
|
// =================
|
|
// === Constants ===
|
|
// =================
|
|
|
|
/** The path of this file. */
|
|
const THIS_PATH = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)))
|
|
/** This must be port `8080` because it is defined as such in AWS. */
|
|
const PORT = 8080
|
|
const HTTP_STATUS_OK = 200
|
|
// `outputPath` does not have to be a real directory because `write` is `false`,
|
|
// meaning that files will not be written to the filesystem.
|
|
// However, the path should still be non-empty in order for `esbuild.serve` to work properly.
|
|
const ARGS: bundler.Arguments = { outputPath: '/', devMode: true }
|
|
const OPTS = bundler.bundlerOptions(ARGS)
|
|
OPTS.entryPoints.push(
|
|
path.resolve(THIS_PATH, 'src', 'index.html'),
|
|
path.resolve(THIS_PATH, 'src', 'index.tsx'),
|
|
path.resolve(THIS_PATH, 'src', 'serviceWorker.ts')
|
|
)
|
|
OPTS.write = false
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
OPTS.loader = { '.html': 'copy' }
|
|
|
|
// ===============
|
|
// === Watcher ===
|
|
// ===============
|
|
|
|
async function watch() {
|
|
const builder = await esbuild.context(OPTS)
|
|
await builder.watch()
|
|
await builder.serve({
|
|
port: PORT,
|
|
servedir: OPTS.outdir,
|
|
onRequest(args) {
|
|
if (args.status !== HTTP_STATUS_OK) {
|
|
console.error(
|
|
chalk.red(`HTTP error ${args.status} when serving path '${args.path}'.`)
|
|
)
|
|
}
|
|
},
|
|
})
|
|
}
|
|
|
|
void watch()
|