Last active
April 30, 2017 18:36
-
-
Save inogo/8834b2dd8fb66ecd1bf23b4dd2739fa0 to your computer and use it in GitHub Desktop.
NodeJS proxy for PHP development server. Usable for serving static content.
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
#!/usr/bin/env node | |
let express = require('express'), | |
logger = require('morgan'), | |
proxy = require('express-http-proxy'); | |
let php = process.argv.length > 2 ? process.argv[2] : '127.0.0.1:8080'; | |
let staticResult = express.static(process.cwd()); | |
let proxyResult = proxy(php); | |
function result(req, res, next) { | |
if (req.path.match(/\.php/i)) { | |
return proxyResult(req, res, next); | |
} | |
return next(); | |
} | |
let app = express() | |
.use(logger('dev')) | |
.use(result) | |
.use(staticResult) | |
.use(proxyResult); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment