Skip to content

Commit

Permalink
Merge pull request #172 from appwrite/feat-cache-middleware
Browse files Browse the repository at this point in the history
feat: cache middleware
  • Loading branch information
TorstenDittmann authored Oct 4, 2023
2 parents 092f725 + 20c497b commit 1aad981
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 9 additions & 0 deletions server/cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @returns {import('express').RequestHandler}
*/
export function cache() {
return function (_req, res, next) {
res.setHeader('Cache-Control', 'max-age=3600, no-cache');
next();
}
}
6 changes: 2 additions & 4 deletions server/main.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import express from 'express';
import compression from 'compression'
import { cache } from './cache.js';
import { sitemap } from './sitemap.js'
import { handler } from '../build/handler.js';

async function main() {
const app = express();
app.use(cache());
app.use(compression());
app.use(await sitemap());
app.use(function (_req, res, next) {
res.setHeader('Cache-Control', 'max-age=3600, no-cache');
next();
});
app.use(handler);
app.listen(3000, () => {
console.log('Listening on http://0.0.0.0:3000');
Expand Down

0 comments on commit 1aad981

Please sign in to comment.