-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
52 lines (39 loc) · 926 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* External dependencies
*/
const express = require( 'express' );
const compression = require( 'compression' );
const http = require( 'http' );
/**
* App initialization
*/
const app = express();
const server = http.Server( app );
/**
* Constants
*/
const REGEXP_VALID_PATH = /^\/($|plan\/(new|\w+(\/workout(\/\d+)?)?)|settings|privacy|about)$/;
const PORT = process.env.PORT || 3000;
/**
* Middlewares
*/
app.use( compression() );
if ( ! process.env.DISABLE_SERVE_STATIC ) {
app.use( express.static( __dirname + '/public' ) );
}
/**
* Routes
*/
app.get( '*', function( request, response ) {
if ( ! REGEXP_VALID_PATH.test( request.path.replace( /.\/$/, '' ) ) ) {
response.status( 404 );
}
response.sendFile( __dirname + '/public/index.html' );
} );
/**
* Start server
*/
server.listen( PORT, function() {
/* eslint-disable no-console */
console.log( 'Listening on port %d...', PORT );
} );