Skip to content

Commit

Permalink
Redirect www
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Apr 2, 2022
1 parent bf095bf commit d6c2648
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions plugins/redirector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import fp from 'fastify-plugin'

export default fp(async function (fastify, opts) {
fastify.addHook('onRequest', async (request, reply) => {
if (fastify.config.ENV === 'production' && request.hostname.startsWith('www')) {
reply.redirect(308, `${fastify.config.DOMAIN}${request.path}`)
}
})
}, {
name: 'redirector',
dependencies: ['env']
})

0 comments on commit d6c2648

Please sign in to comment.