Skip to content

Instantly share code, notes, and snippets.

@ys-qb
Created May 11, 2014 12:55
Show Gist options
  • Save ys-qb/00075133d4b7d5d1f02d to your computer and use it in GitHub Desktop.
Save ys-qb/00075133d4b7d5d1f02d to your computer and use it in GitHub Desktop.
override web files depending on site path
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);
├── 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