Created
December 19, 2017 13:08
-
-
Save zdenekkostal/d2e727645171be5385ba81ed183d4190 to your computer and use it in GitHub Desktop.
Express proxy serving static
This file contains hidden or 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 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