-
Notifications
You must be signed in to change notification settings - Fork 2
/
openbiz-ui.js
69 lines (68 loc) · 1.94 KB
/
openbiz-ui.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
64
65
66
67
68
69
'use strict';
var path = require('path'),
express = require('express'),
fs = require('fs'),
crypto = require('crypto'),
caches = [];
module.exports = function(app){
return {
context:app,
libUrl:null,
_libPath: path.join(__dirname,'ui'),
loadToRoute:function(routePrefix)
{
this.libUrl = routePrefix;
this.context.get(routePrefix+'/main.js',this.getOpenbizUI());
this.context.get(routePrefix+'/vendor/openbiz/openbiz.css',this.getOpenbizCSS());
this.context.use(routePrefix,express.static(this._libPath));
return this;
},
getOpenbizUI:function(){
var self = this;
return function(req,res){
if(caches.hasOwnProperty('main.js') && process.env.NODE_ENV=='production'){
res.set('Content-Type','application/javascript');
res.send(200,caches['main.js']);
}else{
switch(process.env.NODE_ENV){
case "development":
default:
var uiFile = "main.js"
break;
case "production":
var uiFile = "main.min.js"
break;
}
var uiData = fs.readFileSync(path.join(__dirname,'ui',uiFile));
uiData = "var openbizUrl = '"+self.libUrl+"';\n" + uiData;
caches['main.js'] = uiData;
res.set('Content-Type','application/javascript');
res.send(200,uiData);
}
}
},
getOpenbizCSS:function(){
var self = this;
return function(req,res){
if(caches.hasOwnProperty('openbiz.css') && process.env.NODE_ENV=='production'){
res.set('Content-Type','text/css');
res.send(200,caches['openbiz.css']);
}else{
switch(process.env.NODE_ENV){
case "development":
default:
var uiFile = "openbiz.css"
break;
case "production":
var uiFile = "openbiz.min.css"
break;
}
var uiData = fs.readFileSync(path.join(__dirname,'ui',"vendor","openbiz",uiFile));
caches['openbiz.css'] = uiData;
res.set('Content-Type','text/css');
res.send(200,uiData);
}
}
}
};
}