Skip to content

Instantly share code, notes, and snippets.

@evdama
Created July 9, 2019 14:29
Show Gist options
  • Save evdama/979b36c4f9772ea1a8cc1ad4fac62e1e to your computer and use it in GitHub Desktop.
Save evdama/979b36c4f9772ea1a8cc1ad4fac62e1e to your computer and use it in GitHub Desktop.
index.ts with cache control
// TODO: replace type any for request and response
// Start writing Firebase Functions
// https://firebase.google.com/docs/functions/typescript
const functions = require('firebase-functions');
// We have to import the built version of the server middleware.
const { app } = require('../__sapper__/build/server/server');
const oneHour = 60 * 60
const oneDay = oneHour * 24
const oneWeek = oneDay * 7
const oneMonth = oneWeek * 4
app.get('/', (request: any, response: any) => {
response.set(
'Cache-Control',
`public, max-age=${oneWeek}, must-revalidate, s-maxage=${oneWeek}, proxy-revalidate, stale-while-revalidate=${oneDay}, stale-if-error=${oneWeek}`
);
response.send(app);
})
exports.ssr = functions
.region('us-central1')
.https.onRequest(app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment