Skip to content

Commit

Permalink
fix: switch to rewrites from isc
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Oct 17, 2023
1 parent 76d8669 commit 80e3fa6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/demo-site/netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ publish = "/packages/demo-site/public"
[dev]
command = "npm run dev -w packages/demo-site"

[[redirects]]
from = "/*"
to = "/.netlify/functions/server"
status = 200

[[headers]]
for = "/build/*"
Expand Down
9 changes: 7 additions & 2 deletions packages/demo-site/server.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import * as build from '@remix-run/dev/server-build'
import { createRequestHandler } from '@netlify/remix-adapter'
import type { Config } from '@netlify/functions'
import type { Context, Config } from '@netlify/functions'

const handler = createRequestHandler({
const handle = createRequestHandler({
build,
mode: process.env.NODE_ENV,
})

const handler = (request: Request, context: Context) => {
console.log('handler')
return handle(request, context)
}

export default handler

export const config: Config = {
Expand Down
5 changes: 4 additions & 1 deletion packages/remix-adapter/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ export function createRequestHandler({
mode?: string
getLoadContext?: GetLoadContextFunction
}): RequestHandler {
console.log('createRequestHandler')
const remixHandler = createRemixRequestHandler(build, mode)

return async (request: Request, context: LoadContext): Promise<Response | void> => {
const start = Date.now()
console.log(`[${request.method}] ${request.url}`)
try {
const loadContext = (await getLoadContext?.(request, context)) || context

const response = await remixHandler(request, loadContext)

// A useful header for debugging
response.headers.set('x-nf-runtime', 'Node')

console.log(`[${response.status}] ${request.url} (${Date.now() - start}ms)`)
return response
} catch (error: unknown) {
console.error(error)
Expand Down

0 comments on commit 80e3fa6

Please sign in to comment.