-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (32 loc) · 938 Bytes
/
index.js
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
/*
* @file index.coffee
* @author Will Steinmetz
* This Express middleware provides basic functionality similar to the
* respond_to method.
*/
var defaultExtension, determineExtension, setDefaultExtension;
defaultExtension = 'html';
determineExtension = function(req, res, next) {
var format, formatRegex, respondToRegex;
respondToRegex = /\.\w+$/;
format = req.url.match(respondToRegex);
req.format = defaultExtension;
if (format != null) {
req.format = format[0].replace(/^\./, '');
}
if (format != null) {
formatRegex = new RegExp((format[0].replace('.', '\.')) + "$");
req.url = req.url.replace(formatRegex, '');
}
return next();
};
setDefaultExtension = function(extension) {
if (extension != null) {
return defaultExtension = extension;
}
};
module.exports = {
determineExtension: determineExtension,
setDefaultExtension: setDefaultExtension
};
//# sourceMappingURL=index.js.map