forked from course-one/browser-rendering-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
25 lines (20 loc) · 781 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
const express = require( 'express' );
const path = require( 'path' );
// create react app
const app = express();
// return file immediately (parent directory)
app.get( '/:file', ( req, res ) => {
res.sendFile( path.resolve( __dirname, req.params.file ) );
} );
// return file immediately (nested directory)
app.get( '/:dir/:file', ( req, res ) => {
res.sendFile( path.resolve( __dirname, req.params.dir, req.params.file ) );
} );
// return a file with provided delay
app.get( '/:delay/:dir/:file', ( req, res ) => {
setTimeout( () => {
res.sendFile( path.resolve( __dirname, req.params.dir, req.params.file ) );
}, Number( req.params.delay ) );
} );
// serve express application
app.listen( 8088, () => console.log( 'Server started on port: 8088' ) );