Skip to content

Commit

Permalink
fix: redirect www subdomain to apex domain
Browse files Browse the repository at this point in the history
  • Loading branch information
wKovacs64 committed Aug 5, 2022
1 parent 5e883bf commit f452ff0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ const isDev = process.env.NODE_ENV === 'development';

const app = express();

// redirect 'www' subdomain to the apex domain
app.use((req, res, next) => {
if (req.hostname.startsWith('www')) {
const apexHostname = req.hostname.replace('www.', '');
res.redirect(301, `${req.protocol}://${apexHostname}${req.originalUrl}`);
} else {
next();
}
});

app.use((req, res, next) => {
// miscellaneous headers
res.set('X-Fly-Region', process.env.FLY_REGION ?? 'unknown');
Expand Down

0 comments on commit f452ff0

Please sign in to comment.