Skip to content

Instantly share code, notes, and snippets.

@zdenekkostal
Created December 19, 2017 13:08
Show Gist options
  • Select an option

  • Save zdenekkostal/d2e727645171be5385ba81ed183d4190 to your computer and use it in GitHub Desktop.

Select an option

Save zdenekkostal/d2e727645171be5385ba81ed183d4190 to your computer and use it in GitHub Desktop.
Express proxy serving static
const express = require('express')
const proxy = require('express-http-proxy')
const app = express()
const packageJson = require('./package.json')
const PORT = 4500
const DELAY = 1000
app.use(express.static('build/'))
app.use(
'/',
proxy(packageJson.proxy, {
proxyReqPathResolver: function (req) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
resolve(req.path)
}, DELAY)
})
}
})
)
console.log(`Running against ${packageJson.proxy} on localhost:${PORT}`)
app.listen(PORT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment