-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
78 lines (67 loc) · 1.78 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const helmet = require( 'helmet' );
const compression = require( 'compression' );
const express = require( 'express' );
const app = express();
const port = 3000;
// EJS
app.set( 'views', './views' );
app.set( 'view engine', 'ejs' );
// Security
function initHelmet(app,helmet) {
app.use( helmet.contentSecurityPolicy( {
directives: {
defaultSrc: ['\'self\''],
baseUri: ['\'self\''],
blockAllMixedContent: [],
fontSrc: ['\'self\'', 'https:', 'data:'],
frameAncestors: ['\'self\''],
imgSrc: ['\'self\'', 'data:', 'edt.univ-evry.fr'],
objectSrc: ['none'],
scriptSrc: ['\'self\''],
scriptSrcAttr: ['none'],
styleSrc: ['\'self\'', 'https:', '\'unsafe-inline\''],
upgradeInsecureRequests: []
}
} ) );
app.use(helmet.dnsPrefetchControl());
app.use(helmet.expectCt());
app.use(helmet.frameguard());
app.use(helmet.hidePoweredBy());
app.use(helmet.hsts());
app.use(helmet.ieNoOpen());
app.use(helmet.noSniff());
app.use(helmet.permittedCrossDomainPolicies());
app.use(helmet.referrerPolicy());
app.use(helmet.xssFilter());
}
initHelmet( app, helmet );
//Performance
app.use( compression( { level: 9 } ) );
// Static
app.use( express.static( 'public' ) );
// Routes
app.get( '/', ( req, res ) => {
res.render( 'home' );
} );
app.get( '/cours-profs', ( req, res ) => {
res.render( 'cours-profs' );
} );
app.get( '/outils', ( req, res ) => {
res.render( 'outils' );
} );
app.get( '/contact', ( req, res ) => {
res.render( 'contact' );
} );
// Search
app.get( '/search/:query?', ( req, res ) => {
const { params: { query } } = req;
res.json( { search: query } );
} );
// Error page not found
app.use( ( req, res, next ) => {
res.status( 404 );
res.render( 'errors/404' );
} );
app.listen( port, () => {
console.log( `Server listening at http://localhost:${port}` );
} );