-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (38 loc) · 1.17 KB
/
index.js
File metadata and controls
40 lines (38 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
* Copyright (c) 2012 Niall O'Higgins, all rights reserved
* Apres is distributed freely under the MIT license
* See http://apres.github.com/ for details
*
* Convenience middleware for Node.JS / Express.
*
* In your Express app setup you can do:
*
* var apres = require('apres');
*
* Now when you are setting up your middlewares, routes, etc you can add:
*
* apres.helpExpress(app);
*
* Which will automagically serve up static apres assets from /apres/
*
*/
var express = require('express')
, path = require('path');
exports.helpExpress = function(app) {
var basePath = __dirname;
// If not installed as an NPM module, ie test mode
// This is kind of a hack for apres not being a dependency of itself at the moment.
if (basePath.indexOf('node_modules') === -1) {
var staticServer = express.static(basePath);
app.get('/apres/*', function(req, res, next) {
req.url = req.url.slice("/apres".length, req.url.length);
staticServer(req, res, next);
});
} else {
basePath = path.dirname(basePath);
var staticServer = express.static(basePath);
app.get('/apres/*', function(req, res, next) {
staticServer(req, res, next);
});
}
}