/
remoteServer.js
33 lines (29 loc) · 1.06 KB
/
remoteServer.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
//---------------------------------------------------------------------
// Remote server(virtual host)
//---------------------------------------------------------------------
const path = require('path')
const chalk = require('chalk')
const logger = require('morgan')
const express = require('express')
const cookieParser = require('cookie-parser')
const bodyParser = require('body-parser')
const jsonServer = require('json-server')
// Returns an Express server
const app = express()
app.set('port', (process.env.PORT || 5001))
// express middleware
app.use(logger('dev'))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(cookieParser())
// Set default middlewares (logger, static, cors and no-cache)
app.use(jsonServer.defaults())
app.use('/api', jsonServer.router(path.join(__dirname, './api/db.json')))
// start server
app.listen(app.get('port'), () => {
/* eslint-disable no-console */
console.log(chalk.cyan(`The remote server is running at http://localhost:${app.get('port')}`))
if (process.send) {
process.send('online')
}
})