-
Notifications
You must be signed in to change notification settings - Fork 1
/
proxy.js
39 lines (35 loc) · 1.14 KB
/
proxy.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
'use strict'
require('colors')
const fs = require('fs')
const env = process.env.NODE_ENV === 'development' ? 'dev' : 'prod'
/**
* read proxy table according to HOSTALIAS
*/
const proxyTableConfig = require('./proxy-table.js')
const hostalias = process.env.HOSTALIAS || 'prod'
const table = proxyTableConfig[hostalias]
/**
* Merge dev proxy table if exists
*/
const devProxyTablePath = './proxy-table.dev.js'
if (fs.existsSync(devProxyTablePath)) {
console.log('Using proxy-table.dev.js'.green.bold)
Object.assign(table, require(devProxyTablePath))
} else {
if (env === 'dev') {
setTimeout(function () {
const errMsg = ' proxy-table.dev.js is require in development mode '
const bar = '!'.repeat(errMsg.length)
console.error(bar.red.bold)
console.error(errMsg.red.bold)
console.error(' cp proxy-table.dev.example.js proxy-table.dev.js'.red.bold)
console.error(bar.red.bold)
}, 5000)
}
console.log('Host alias: %s'.green.bold, hostalias)
}
const proxy = require('express-http-proxy')
module.exports = function (app) {
// add more proxy entries if needed
app.use('/api/', proxy(table.portal))
}