Skip to content

Commit

Permalink
chore: add custom header
Browse files Browse the repository at this point in the history
In this case it is a header to the repository
  • Loading branch information
bjarneo committed May 1, 2024
1 parent c24d2c7 commit 55118fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import downloadRoute from './server/controllers/download.js';
import healthzRoute from './server/controllers/healthz.js';
import secretRoute from './server/controllers/secret.js';
import statsRoute from './server/controllers/stats.js';
import customHeaders from './server/plugins/custom-headers.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand Down Expand Up @@ -89,6 +90,8 @@ if (!isDev) {
fs.writeFileSync(index, dom.serialize());
}

fastify.register(customHeaders);

fastify.register(rateLimit, {
prefix: '/api/',
max: config.get('rateLimit.max'),
Expand Down
10 changes: 10 additions & 0 deletions server/plugins/custom-headers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import fp from 'fastify-plugin';

export default fp((fastify, _, done) => {
fastify.decorate('customHeaders', async (_, res) => {
res.header('X-Github', 'https://github.com/HemmeligOrg/Hemmelig.app');
});

fastify.addHook('onRequest', fastify.customHeaders);
done();
});

0 comments on commit 55118fe

Please sign in to comment.