2018-02-25 03:00:43 +01:00
|
|
|
const express = require('express');
|
2017-08-24 23:54:02 +02:00
|
|
|
const busboy = require('connect-busboy');
|
|
|
|
const helmet = require('helmet');
|
|
|
|
const storage = require('../storage');
|
|
|
|
const config = require('../config');
|
2018-02-06 23:31:18 +01:00
|
|
|
const auth = require('../middleware/auth');
|
|
|
|
const owner = require('../middleware/owner');
|
|
|
|
const language = require('../middleware/language');
|
2017-08-24 23:54:02 +02:00
|
|
|
const pages = require('./pages');
|
2018-02-06 23:31:18 +01:00
|
|
|
|
2017-08-29 20:19:21 +02:00
|
|
|
const IS_DEV = config.env === 'development';
|
2018-02-06 23:31:18 +01:00
|
|
|
const ID_REGEX = '([0-9a-fA-F]{10})';
|
|
|
|
const uploader = busboy({
|
|
|
|
limits: {
|
|
|
|
fileSize: config.max_file_size
|
|
|
|
}
|
|
|
|
});
|
2017-08-24 23:54:02 +02:00
|
|
|
|
|
|
|
module.exports = function(app) {
|
|
|
|
app.use(helmet());
|
|
|
|
app.use(
|
|
|
|
helmet.hsts({
|
|
|
|
maxAge: 31536000,
|
2017-08-29 20:19:21 +02:00
|
|
|
force: !IS_DEV
|
2017-08-24 23:54:02 +02:00
|
|
|
})
|
|
|
|
);
|
2017-11-30 22:41:09 +01:00
|
|
|
if (!IS_DEV) {
|
|
|
|
app.use(
|
|
|
|
helmet.contentSecurityPolicy({
|
|
|
|
directives: {
|
|
|
|
defaultSrc: ["'self'"],
|
|
|
|
connectSrc: [
|
|
|
|
"'self'",
|
|
|
|
'https://sentry.prod.mozaws.net',
|
|
|
|
'https://www.google-analytics.com'
|
|
|
|
],
|
|
|
|
imgSrc: ["'self'", 'https://www.google-analytics.com'],
|
|
|
|
scriptSrc: ["'self'"],
|
2018-02-26 20:48:28 +01:00
|
|
|
styleSrc: ["'self'", 'https://code.cdn.mozilla.net'],
|
2017-11-30 22:41:09 +01:00
|
|
|
fontSrc: ["'self'", 'https://code.cdn.mozilla.net'],
|
|
|
|
formAction: ["'none'"],
|
|
|
|
frameAncestors: ["'none'"],
|
|
|
|
objectSrc: ["'none'"],
|
|
|
|
reportUri: '/__cspreport__'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2017-11-06 22:36:36 +01:00
|
|
|
app.use(function(req, res, next) {
|
|
|
|
res.set('Pragma', 'no-cache');
|
|
|
|
res.set('Cache-Control', 'no-cache');
|
|
|
|
next();
|
|
|
|
});
|
2018-02-25 03:00:43 +01:00
|
|
|
app.use(express.json());
|
2018-02-06 23:31:18 +01:00
|
|
|
app.get('/', language, pages.index);
|
|
|
|
app.get('/legal', language, pages.legal);
|
2017-08-24 23:54:02 +02:00
|
|
|
app.get('/jsconfig.js', require('./jsconfig'));
|
2018-02-06 23:31:18 +01:00
|
|
|
app.get(`/share/:id${ID_REGEX}`, language, pages.blank);
|
|
|
|
app.get(`/download/:id${ID_REGEX}`, language, pages.download);
|
|
|
|
app.get('/completed', language, pages.blank);
|
|
|
|
app.get('/unsupported/:reason', language, pages.unsupported);
|
|
|
|
app.get(`/api/download/:id${ID_REGEX}`, auth, require('./download'));
|
|
|
|
app.get(`/api/exists/:id${ID_REGEX}`, require('./exists'));
|
|
|
|
app.get(`/api/metadata/:id${ID_REGEX}`, auth, require('./metadata'));
|
|
|
|
app.post('/api/upload', uploader, require('./upload'));
|
|
|
|
app.post(`/api/delete/:id${ID_REGEX}`, owner, require('./delete'));
|
|
|
|
app.post(`/api/password/:id${ID_REGEX}`, owner, require('./password'));
|
|
|
|
app.post(`/api/params/:id${ID_REGEX}`, owner, require('./params'));
|
|
|
|
app.post(`/api/info/:id${ID_REGEX}`, owner, require('./info'));
|
2017-08-24 23:54:02 +02:00
|
|
|
|
|
|
|
app.get('/__version__', function(req, res) {
|
|
|
|
res.sendFile(require.resolve('../../dist/version.json'));
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get('/__lbheartbeat__', function(req, res) {
|
|
|
|
res.sendStatus(200);
|
|
|
|
});
|
|
|
|
|
2017-08-25 19:03:49 +02:00
|
|
|
app.get('/__heartbeat__', async (req, res) => {
|
2017-08-24 23:54:02 +02:00
|
|
|
try {
|
|
|
|
await storage.ping();
|
|
|
|
res.sendStatus(200);
|
|
|
|
} catch (e) {
|
|
|
|
res.sendStatus(500);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|