Created
May 11, 2014 12:55
-
-
Save ys-qb/00075133d4b7d5d1f02d to your computer and use it in GitHub Desktop.
override web files depending on site path
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
var fs = require('fs'); | |
var express = require('express'); | |
var app = express(); | |
var path = require('path'); | |
app.get('/:site/:file', function(req, res, next){ | |
var filePath = path.join(__dirname + '/sites' , req.params.site, req.params.file); | |
if (fs.existsSync(filePath)){ | |
res.sendfile(filePath); | |
}else { | |
next(); | |
} | |
}); | |
//remove site | |
app.use(function(req, res, next) { | |
if (req.url.indexOf('/', 1) !== -1) { | |
req.url = req.url.slice(req.url.indexOf('/', 1)); | |
} | |
console.error('url', req.url); | |
next(); | |
}); | |
app.use(express.static(__dirname + '/public')); | |
app.listen(8080); |
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
├── app.js | |
├── public | |
│ ├── index.html | |
│ ├── logo.png | |
│ ├── main.css | |
│ └── main.js | |
└── sites | |
└── asite | |
├── logo.png | |
├── main_site.css | |
└── main_site.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment