25 lines
964 B
JavaScript
25 lines
964 B
JavaScript
import _ from "lodash";
|
|
import { log } from "../../utils/log";
|
|
import serverParamsGen from "./server-params-gen";
|
|
import isDevelopment from "../../utils/is-development";
|
|
import { restartWatcher, watcherRestartAvailable, } from "./watcher-esbuild-ctx";
|
|
export default async function startServer() {
|
|
const serverParams = await serverParamsGen();
|
|
const server = Bun.serve(serverParams);
|
|
const is_dev = isDevelopment();
|
|
global.BUNEXT_SERVER = server;
|
|
log.server(`http://${server.hostname}:${server.port}`);
|
|
if (is_dev) {
|
|
// Watchdog: periodically re-create the FS watcher in case it went
|
|
// stale and stopped receiving events. Skipped while a recent restart
|
|
// (e.g. by fullRebuild) is still fresh so the watcher isn't churned
|
|
// twice in a row.
|
|
setInterval(() => {
|
|
if (watcherRestartAvailable()) {
|
|
restartWatcher();
|
|
}
|
|
}, 5000);
|
|
}
|
|
return server;
|
|
}
|