forked from trustyoo86/parcel-browsersync-proxy-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (34 loc) · 813 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
/**
* server example
*
* @author kern
* @since 2018.02.21 - draft
*/
'use strict'
const express = require('express');
const bundler = require('./dev/parcel.config')
const path = require('path')
// node env mode variable
const isProd = process.env.NODE_ENV === 'production'
// express app
const app = express();
// app use bundler middleware if production mode
if (isProd) {
app.use(bundler.middleware())
}
// setting static dist assets
app.use(express.static(path.join(__dirname, 'dist')))
// initialize router
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'dist', 'index.html'))
})
// api testing
app.get('/api', (req, res) => {
res.status(200).json({
'test': 'ok'
})
})
// listen 8080 port
app.listen(8080, () => {
console.log('application server listen port 8080')
})