-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev-server.js
42 lines (34 loc) · 1.05 KB
/
dev-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
41
42
var opn = require('opn')
var path = require('path')
var express = require('express')
var proxyMiddleware = require('http-proxy-middleware')
// default port where dev server listens for incoming traffic
var port = process.env.PORT || 8080
// automatically open browser, if not set will be false
var autoOpenBrowser = true
// Define HTTP proxies to your custom API backend
// https://github.com/chimurai/http-proxy-middleware
var proxyTable = {}
var app = express()
// proxy api requests
Object.keys(proxyTable).forEach(function (context) {
var options = proxyTable[context]
if (typeof options === 'string') {
options = { target: options }
}
app.use(proxyMiddleware(options.filter || context, options))
})
// serve pure static assets
app.use('/', express.static('./docs'))
app.use('/blob', express.static('./docs/blob'))
var uri = 'http://localhost:' + port
console.log('> NaniKore is listening at ' + uri + '\n')
module.exports = app.listen(port, function (err) {
if (err) {
console.log(err)
return
}
if (autoOpenBrowser) {
opn(uri)
}
})