forked from fontello/fontello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assets.js
63 lines (39 loc) · 1.24 KB
/
assets.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
/*global nodeca*/
// 3rd-party
var Mincer = require('mincer');
// internal
var logger = nodeca.logger.getLogger('server.assets');
////////////////////////////////////////////////////////////////////////////////
var server;
// Formats and writes log event into our logger
//
function assets_logger(level, event) {
logger[level]('%s - "%s %s HTTP/%s" %d "%s" - %s',
event.remoteAddress,
event.method,
event.url,
event.httpVersion,
event.code,
event.headers['user-agent'],
event.message);
}
// helper to pass request to the lazy-loaded miner server
function call_mincer_server(req, res) {
var assets;
if (!server) {
assets = nodeca.runtime.assets,
server = new Mincer.Server(assets.environment, assets.manifest);
server.log = assets_logger;
}
server.handle(req, res);
}
////////////////////////////////////////////////////////////////////////////////
module.exports = function (params, callback) {
if (!this.origin.http) {
callback({statusCode: 400, body: "HTTP ONLY"});
return;
}
this.origin.http.req.url = params.path;
call_mincer_server(this.origin.http.req, this.origin.http.res);
};