forked from ionic-team/ionic-legacy-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
34 lines (28 loc) · 998 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const Sentry = require('@sentry/node');
const express = require('express');
const parseurl = require('parseurl');
const path = require('path');
const app = express();
app.set('trust proxy', true);
if (process.env.SENTRY_DSN) {
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.SENTRY_ENVIRONMENT
});
}
// The Sentry request handler must be the first middleware on the app
app.use(Sentry.Handlers.requestHandler());
app.use((_, res, next) => {
res.set('X-Robots-Tag', 'noindex, nofollow');
next();
});
app.use(express.static(path.join(__dirname, '_site'), { maxAge: '2h' }));
app.get('/', (_, res) => res.redirect(301, '/docs/v3/'));
// The Sentry error handler must be before any other error middleware
app.use(Sentry.Handlers.errorHandler());
app.use((_, res) => {
res.status(404).sendFile(`${__dirname}/_site/404.html`);
});
const listener = app.listen(process.env.PORT || 3000, () => {
console.log(`Listening on port ${listener.address().port}`);
});