Skip to content

Commit

Permalink
short circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis committed Mar 2, 2024
1 parent a39cc27 commit 50b1c30
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 46 deletions.
78 changes: 41 additions & 37 deletions packages/houdini/src/runtime/router/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,43 +74,47 @@ export function _serverHandler<ComponentType = unknown>({
return yoga(request)
}

// maybe its a session-related request
// const authResponse = await handle_request({
// url,
// config: config_file,
// session_keys,
// headers: request.headers,
// })
// if (authResponse) {
// return authResponse
// }

// the request is for a server-side rendered page

// find the matching url
const [match] = find_match(manifest, url)

// call the framework-specific render hook with the latest session
const rendered = await on_render({
url,
match,
session: await get_session(request.headers, session_keys),
manifest,
componentCache,
})
if (rendered) {
return rendered
}

// if we got this far its not a page we recognize
return new Response('404', { status: 404 })
return new Response('OK', { status: 200 })
}
}

export const serverAdapterFactory = (
args: Parameters<typeof _serverHandler>[0]
): ReturnType<typeof createAdapter> => {
return createAdapter(_serverHandler(args))
}

export type ServerAdapterFactory = typeof serverAdapterFactory
// // // maybe its a session-related request
// // const authResponse = await handle_request({
// // url,
// // config: config_file,
// // session_keys,
// // headers: request.headers,
// // })
// // if (authResponse) {
// // return authResponse
// // }

// // // the request is for a server-side rendered page

// // // find the matching url
// // const [match] = find_match(manifest, url)

// // // call the framework-specific render hook with the latest session
// // const rendered = await on_render({
// // url,
// // match,
// // session: await get_session(request.headers, session_keys),
// // manifest,
// // componentCache,
// // })
// // if (rendered) {
// // return rendered
// // }

// // // if we got this far its not a page we recognize
// // return new Response('404', { status: 404 })
// // }
// }

// export const serverAdapterFactory = (
// args: Parameters<typeof _serverHandler>[0]
// ): ReturnType<typeof createAdapter> => {
// return createAdapter(_serverHandler(args))
// }

// export type ServerAdapterFactory = typeof serverAdapterFactory
17 changes: 8 additions & 9 deletions packages/houdini/src/runtime/router/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ type ServerHandlerArgs = {

// the actual server implementation changes from runtime to runtime
// so we want a single function that can be called to get the server
export async function handle_request(args: ServerHandlerArgs) {
export async function handle_request(args: ServerHandlerArgs): Promise<Response | undefined> {
const plugin_config = args.config.router ?? {}
// if the project is configured to authorize users by redirect then
// we might need to set the session value
// if (
// false &&
// plugin_config.auth &&
// 'redirect' in plugin_config.auth &&
// args.url.startsWith(plugin_config.auth.redirect)
// ) {
// return await redirect_auth(args)
// }
if (
plugin_config.auth &&
'redirect' in plugin_config.auth &&
args.url.startsWith(plugin_config.auth.redirect)
) {
return await redirect_auth(args)
}
}

async function redirect_auth(args: ServerHandlerArgs): Promise<Response> {
Expand Down

0 comments on commit 50b1c30

Please sign in to comment.