-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
36 lines (28 loc) · 1.07 KB
/
server.js
File metadata and controls
36 lines (28 loc) · 1.07 KB
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
require('colors');
const moduleAlias = require('module-alias');
const chokidar = require('chokidar');
const invalidate = require('invalidate-module');
const path = require('path');
const morgan = require('morgan');
const isProduction = process.env.ENV === 'production';
/* workaround to avoid crash when loading [art] library on server */
global.document = { createElement: () => {}, };
moduleAlias.addAlias('react-native', 'react-native-web');
const watcher = chokidar.watch('./src', { ignoreInitial: true });
watcher.on('all', (event, filename) => {
console.log(' HOT PUSH! '.bgMagenta, filename.green, 'now in sync!');
invalidate(path.resolve(filename));
});
const PORT = 3005,
express = require('express'),
server = express();
server.set('view engine', 'ejs');
server.use(express.static(isProduction ? 'web' : 'static'));
server.use(morgan('dev'));
server.use((req, res, next) => {
const router = require('./src/server/router');
router(req, res, next);
});
server.listen(PORT, () => {
console.log('Your api-server now listening at', ` localhost:${PORT} `.bgGreen, ':p');
});