Created
August 20, 2018 13:10
-
-
Save kizzlebot/94d958814ef8cc8ea9ec75b5c3963556 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const proxy = require("http-proxy-middleware"); | |
const proxyConf = require('./proxy-config'); | |
const _ = require('lodash'); | |
const morgan = require('morgan'); | |
const R = require('ramda'); | |
// var proxyFilter = (pathName, req) => pathName.match(/^\/api|^\/login$|^\/logout$|^\/proxy/); | |
const proxyFilter = R.pipe(R.match(/^\/api|^\/login$|^\/logout$|^\/proxy/), R.complement(R.isEmpty)); | |
const strIncludes = (str, inc) => str.includes(inc); | |
const buildOveriderMiddleware = (conf) => (req, res, next) => { | |
const url = req.originalUrl; | |
const doOverride = _.chain(conf) | |
.keys() | |
.reduce((prev, curr, acc) => { | |
if (prev !== false){ | |
return prev; | |
} | |
else if (url.includes(curr)){ | |
return curr; | |
} | |
return prev; | |
}, false) | |
.value(); | |
if (!doOverride){ | |
return next(); | |
} | |
const { | |
response = {}, | |
contentType = 'application/json;charset=UTF-8' | |
} = conf[doOverride]; | |
res.writeHead(200, { | |
'Content-Type': contentType | |
}); | |
res.end(JSON.stringify(response)); | |
}; | |
module.exports = { | |
open: false, | |
//logLevel: 'silent', | |
server: { | |
baseDir: [ | |
`${process.env.HOME}/Documents/dev/kylo-plugins/ui-base-feed-stepper/src/main/resources`, | |
`${process.env.HOME}/Documents/dev/kylo-plugins/ui-set-bucketing-options-processor-template/src/main/resources/static`, | |
`${process.env.HOME}/Documents/dev/kylo-plugins/ui-workspace-execution-processor-template/src/main/resources/static`, | |
`${process.env.HOME}/Documents/dev/kylo/plugins/ui-sqoop-table-data-processor-template/src/main/resources/static`, | |
'src/main/resources/static', | |
'target/classes/static', | |
], | |
middleware: [ | |
morgan('dev'), | |
buildOveriderMiddleware(proxyConf), | |
proxy(proxyFilter, { | |
target: process.env.PROXY || "http://localhost:8400/", | |
logLevel: 'silent' | |
}) | |
] | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment