-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
34 lines (25 loc) · 936 Bytes
/
app.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 express = require('express');
const chalk = require('chalk');
const util = require('./util');
const app = express();
// setup global vars
const PORT = process.env.PORT || 8080;
const pub = `${__dirname}/build/public`;
const serverLocation = chalk.bold(`localhost:${PORT}`);
// every time the server gets hit, log it nicely.
app.use('/', (req, res, next) => {
const method = util.formatMethod(req.method);
console.log(`${new Date()} :: ${method} ${req.url}`);
next();
});
console.log(__dirname);
console.log(pub);
// keep all of the resources on /pub
app.use('/pub', express.static(pub, {
extensions: ['css', 'js', 'png', 'jpg'],
}));
// but stick the html pages under the root.
app.use('/', express.static(pub, { extensions: ['html'] }));
console.log(chalk.yellow(`Attempting to listen on ...${serverLocation}`));
app.listen(PORT);
console.log(`${chalk.green('Success!')} Server running on ${serverLocation}\n`);