Version 1.0.1 - can handle non-default routes via handle_fetch_fallback

This commit is contained in:
dab 2025-10-15 17:32:25 +00:00
parent 7a7fbfa42f
commit ca1a993b31
2 changed files with 10 additions and 4 deletions

View file

@ -37,7 +37,7 @@ const wrap_transport_sendbytes = function (ws, msg_bytes) {
return return
} }
const start_server = function ({ context_meta, config, jsbuild_app_frontend, handle_transport_bytes }) { const start_server = function ({ context_meta, config, jsbuild_app_frontend, handle_transport_bytes, handle_fetch_fallback }) {
const make_session_object = (ws) => { const make_session_object = (ws) => {
const map_obj = { const map_obj = {
ws, ws,
@ -130,8 +130,13 @@ const start_server = function ({ context_meta, config, jsbuild_app_frontend, han
resp = new Response('Upgrade failed', { status: 500 }) resp = new Response('Upgrade failed', { status: 500 })
} }
else { else {
if (handle_fetch_fallback !== undefined) {
resp = handle_fetch_fallback(req)
}
if (resp === undefined) {
resp = new Response(null, { status: 404 }) resp = new Response(null, { status: 404 })
} }
}
return resp return resp
}, },
websocket: { websocket: {
@ -225,6 +230,7 @@ const async_run = async function ({
config, config,
jsbuild_app_frontend, jsbuild_app_frontend,
handle_transport_bytes, handle_transport_bytes,
handle_fetch_fallback,
}) { }) {
const active_config = { const active_config = {
// defaults // defaults
@ -239,7 +245,7 @@ const async_run = async function ({
const context_meta = { const context_meta = {
ws_map: new Map(), ws_map: new Map(),
} }
const server = start_server({ context_meta, config: active_config, jsbuild_app_frontend, handle_transport_bytes }) const server = start_server({ context_meta, config: active_config, jsbuild_app_frontend, handle_transport_bytes, handle_fetch_fallback })
console.info(`framerock app now running at ${active_config.hostname}:${active_config.port}`) console.info(`framerock app now running at ${active_config.hostname}:${active_config.port}`)
process.on('SIGINT', async () => { process.on('SIGINT', async () => {
console.log('SIGINT intercepted') console.log('SIGINT intercepted')

View file

@ -1,6 +1,6 @@
{ {
"name": "framerock", "name": "framerock",
"version": "1.0.0", "version": "1.0.1",
"type": "module", "type": "module",
"main": "backend/index.js" "main": "backend/index.js"
} }