Skip to content

Instantly share code, notes, and snippets.

@honzabrecka
Created January 7, 2016 22:51
Show Gist options
  • Save honzabrecka/675608e5b6f79c19db1d to your computer and use it in GitHub Desktop.
Save honzabrecka/675608e5b6f79c19db1d to your computer and use it in GitHub Desktop.
proxy
const fs = require('fs')
const express = require('express')
const proxy = require("http-proxy").createProxyServer({"changeOrigin": true})
const index = './src/index.html'
const port = 3000
const proxyTarget = '...'
const app = express()
app.use('/public', express.static('./target/public'))
app.use('/proxy', (req, res) => proxy.web(req, res, {target: proxyTarget}))
app.get('/', (req, res) => fs.readFile(index, 'utf8', (error, template) => {
if (error) throw new Error(error)
res.send(template)
}))
const server = app.listen(port, () => {
console.log('Server started at http://localhost:' + port)
})
{
"dependencies": {
"express": "4.13.3",
"http-proxy": "1.12.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment