Skip to content

Commit

Permalink
- update to use matchRoute for server adaptor
Browse files Browse the repository at this point in the history
- add named route example
  • Loading branch information
floodfx committed Oct 2, 2022
1 parent cc82780 commit 504ebd1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/deno/import_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"crypto": "https://deno.land/[email protected]/node/crypto.ts",
"events": "https://deno.land/[email protected]/node/events.ts",
"nanoid": "https://deno.land/x/[email protected]/mod.ts",
"path-to-regexp": "https://deno.land/x/[email protected]/index.ts",
"liveviewjs": "../core/dist/liveview.mjs",
"@liveviewjs/examples": "../examples/dist/liveviewjs-examples.mjs"
}
Expand Down
7 changes: 5 additions & 2 deletions packages/deno/src/deno/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
LiveViewRouter,
LiveViewServerAdaptor,
LiveViewWrapperTemplate,
matchRoute,
nanoid,
PubSub,
SerDe,
Expand Down Expand Up @@ -109,13 +110,14 @@ export class DenoOakLiveViewServer implements LiveViewServerAdaptor<DenoMiddlewa
const { getRequestPath } = adaptor;

// look up LiveView for route
const liveview = this.router[getRequestPath()];
if (!liveview) {
const matchResult = matchRoute(this.router, getRequestPath());
if (!matchResult) {
// no LiveView found for route so call next() to
// let a possible downstream route handle the request
await next();
return;
}
const [liveview, mr] = matchResult;

// defer to liveviewjs to handle the request
const rootViewHtml = await handleHttpLiveView(
Expand All @@ -124,6 +126,7 @@ export class DenoOakLiveViewServer implements LiveViewServerAdaptor<DenoMiddlewa
liveview,
adaptor,
this.liveHtmlTemplate,
mr.params,
this.liveTitleOptions,
this.wrapperTemplate
);
Expand Down
2 changes: 2 additions & 0 deletions packages/deno/src/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export {
counterLiveView,
dashboardLiveView,
decarbLiveView,
helloNameLiveView,
helloToggleEmojiLiveView,
jsCmdsLiveView,
paginateLiveView,
Expand Down Expand Up @@ -34,6 +35,7 @@ export {
handleHttpLiveView,
html,
live_title_tag,
matchRoute,
safe,
SessionFlashAdaptor,
SingleProcessPubSub,
Expand Down
2 changes: 2 additions & 0 deletions packages/deno/src/example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
counterLiveView,
dashboardLiveView,
decarbLiveView,
helloNameLiveView,
helloToggleEmojiLiveView,
jsCmdsLiveView,
LiveViewRouter,
Expand Down Expand Up @@ -44,6 +45,7 @@ const lvRouter: LiveViewRouter = {
"/rtcounter": rtCounterLiveView,
"/books": booksLiveView,
"/helloToggle": helloToggleEmojiLiveView,
"/hi/:name": helloNameLiveView,
};

// configure your oak app
Expand Down

0 comments on commit 504ebd1

Please sign in to comment.