Skip to content

Commit

Permalink
Merge pull request #2716 from lpsinger/dont-store-cache-responses
Browse files Browse the repository at this point in the history
Don't store cached responses by default
  • Loading branch information
dakota002 authored Nov 19, 2024
2 parents 95edeb6 + bacb22b commit 00751c7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type RequestHandler, createRequestHandler } from '@remix-run/architect'
import * as build from '@remix-run/dev/server-build'
import { installGlobals } from '@remix-run/node'
import { type APIGatewayProxyStructuredResultV2 } from 'aws-lambda'
import sourceMapSupport from 'source-map-support'

sourceMapSupport.install()
Expand All @@ -13,10 +14,20 @@ const remixHandler = createRequestHandler({

const { CDN_SECRET } = process.env

export const handler: RequestHandler = (event, ...args) => {
export const handler: RequestHandler = async (event, ...args) => {
if (CDN_SECRET && event.headers['x-cdn-secret'] !== CDN_SECRET)
// FIXME: this shouldn't need to be a promise.
// See https://github.com/DefinitelyTyped/DefinitelyTyped/pull/69466
return Promise.resolve({ statusCode: 502 })
return remixHandler(event, ...args)

// By default, don't cache responses.
// This prevents us from showing stale pages. For example, if the user
// logs out and then clicks the "back" button, they should not see a page
// that looks like they are still logged in.
const result = (await remixHandler(
event,
...args
)) as APIGatewayProxyStructuredResultV2
;(result.headers ??= {})['Cache-Control'] ??= 'max-age=0, no-store'
return result
}

0 comments on commit 00751c7

Please sign in to comment.