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
}
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 map_obj = {
ws,
@ -130,7 +130,12 @@ const start_server = function ({ context_meta, config, jsbuild_app_frontend, han
resp = new Response('Upgrade failed', { status: 500 })
}
else {
resp = new Response(null, { status: 404 })
if (handle_fetch_fallback !== undefined) {
resp = handle_fetch_fallback(req)
}
if (resp === undefined) {
resp = new Response(null, { status: 404 })
}
}
return resp
},
@ -225,6 +230,7 @@ const async_run = async function ({
config,
jsbuild_app_frontend,
handle_transport_bytes,
handle_fetch_fallback,
}) {
const active_config = {
// defaults
@ -239,7 +245,7 @@ const async_run = async function ({
const context_meta = {
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}`)
process.on('SIGINT', async () => {
console.log('SIGINT intercepted')

View file

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