vanilla-jet 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Gruntfile.js +2 -2
- package/framework/dipper.js +16 -53
- package/framework/router.js +10 -12
- package/framework/server.js +25 -48
- package/package.json +1 -1
package/Gruntfile.js
CHANGED
|
@@ -176,7 +176,7 @@ module.exports = function(grunt) {
|
|
|
176
176
|
grunt.option('force', true);
|
|
177
177
|
grunt.task.run('clean:' + target);
|
|
178
178
|
});
|
|
179
|
-
grunt.registerTask('default', ['buildLess', 'uglify', 'cleanForce:build', 'concat', 'cleanForce:minified', 'shell:compileTemplates', 'watch']);
|
|
180
|
-
grunt.registerTask('build', ['buildLess', 'uglify', 'cleanForce:build', 'concat', 'cleanForce:minified', 'shell:compileTemplates']);
|
|
179
|
+
grunt.registerTask('default', ['buildLess', 'uglify', 'cleanForce:build', 'concat', 'cleanForce:minified', 'shell:compileTemplates', 'compress', 'watch']);
|
|
180
|
+
grunt.registerTask('build', ['buildLess', 'uglify', 'cleanForce:build', 'concat', 'cleanForce:minified', 'shell:compileTemplates', 'compress']);
|
|
181
181
|
grunt.registerTask('server', ['buildLess']);
|
|
182
182
|
};
|
package/framework/dipper.js
CHANGED
|
@@ -9,12 +9,7 @@ function Dipper(options, shared) {
|
|
|
9
9
|
this.page_title = this.site_title;
|
|
10
10
|
this.description = shared.description;
|
|
11
11
|
this.fbAppId = shared.fbAppId;
|
|
12
|
-
|
|
13
|
-
this.site_url = ((this.options.site_url == 'localhost') ?
|
|
14
|
-
'http://localhost' :
|
|
15
|
-
this.options.site_url) + ':' + this.options.port;
|
|
16
12
|
this.base_dir = path.join(process.cwd(), '/');
|
|
17
|
-
this.base_url = this.site_url + this.options.base_url;
|
|
18
13
|
|
|
19
14
|
// Dirs
|
|
20
15
|
this.dirs = {
|
|
@@ -44,27 +39,19 @@ function Dipper(options, shared) {
|
|
|
44
39
|
}
|
|
45
40
|
|
|
46
41
|
Dipper.prototype.getPageTitle = function() {
|
|
47
|
-
|
|
48
|
-
var obj = this;
|
|
49
|
-
return obj.page_title;
|
|
42
|
+
return this.page_title;
|
|
50
43
|
}
|
|
51
44
|
|
|
52
45
|
Dipper.prototype.getSiteTitle = function() {
|
|
53
|
-
|
|
54
|
-
var obj = this;
|
|
55
|
-
return obj.site_title;
|
|
46
|
+
return this.site_title;
|
|
56
47
|
}
|
|
57
48
|
|
|
58
49
|
Dipper.prototype.getDescription = function() {
|
|
59
|
-
|
|
60
|
-
var obj = this;
|
|
61
|
-
return obj.description;
|
|
50
|
+
return this.description;
|
|
62
51
|
}
|
|
63
52
|
|
|
64
53
|
Dipper.prototype.getFbAppId = function() {
|
|
65
|
-
|
|
66
|
-
var obj = this;
|
|
67
|
-
return obj.fbAppId;
|
|
54
|
+
return this.fbAppId;
|
|
68
55
|
}
|
|
69
56
|
|
|
70
57
|
Dipper.prototype.addMeta = function({name, content, attribute}) {
|
|
@@ -100,11 +87,8 @@ Dipper.prototype.metaTags = function() {
|
|
|
100
87
|
}
|
|
101
88
|
|
|
102
89
|
Dipper.prototype.img = function(filename) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
dir = this.getDir('images', false);
|
|
106
|
-
ret = this.urlTo(dir + filename);
|
|
107
|
-
return ret;
|
|
90
|
+
let dir = this.getDir('images', false);
|
|
91
|
+
return this.urlTo(dir + filename);
|
|
108
92
|
}
|
|
109
93
|
|
|
110
94
|
Dipper.prototype.script = function(filename) {
|
|
@@ -119,17 +103,14 @@ Dipper.prototype.style = function(filename) {
|
|
|
119
103
|
|
|
120
104
|
Dipper.prototype.pdf = function(filename) {
|
|
121
105
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
ret = this.urlTo(dir + filename);
|
|
125
|
-
//console.log(ret);
|
|
126
|
-
return ret;
|
|
106
|
+
let dir = '/assets/pdf/';
|
|
107
|
+
return this.urlTo(dir + filename);
|
|
127
108
|
}
|
|
128
109
|
|
|
129
110
|
Dipper.prototype.getDir = function(dir, full) {
|
|
130
111
|
|
|
131
|
-
|
|
132
|
-
|
|
112
|
+
let obj = this;
|
|
113
|
+
full = (full == undefined) ? true : full;
|
|
133
114
|
|
|
134
115
|
if ( obj.dirs[dir] != undefined ) {
|
|
135
116
|
return (full == true ? obj.baseDir(obj.dirs[dir]) : obj.dirs[dir]);
|
|
@@ -138,32 +119,14 @@ Dipper.prototype.getDir = function(dir, full) {
|
|
|
138
119
|
}
|
|
139
120
|
|
|
140
121
|
Dipper.prototype.baseDir = function(path) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
path = path || '',
|
|
144
|
-
ret = obj.base_dir + path;
|
|
145
|
-
return ret;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
Dipper.prototype.isSecureRequest = function() {
|
|
149
|
-
|
|
150
|
-
var obj = this;
|
|
151
|
-
// Cheking for http or https
|
|
152
|
-
if (/^((http):\/\/)/.test(obj.options.site_url) || /^((localhost))/.test(obj.options.site_url)) {
|
|
153
|
-
return false;
|
|
154
|
-
} else if (/^((https):\/\/)/.test(obj.options.site_url)) {
|
|
155
|
-
return true;
|
|
156
|
-
}
|
|
122
|
+
path = path || '';
|
|
123
|
+
return this.base_dir + path;
|
|
157
124
|
}
|
|
158
125
|
|
|
159
|
-
Dipper.prototype.urlTo = function(route
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
url = obj.base_url + route;
|
|
164
|
-
//url = obj.baseUrl(route, protocol);
|
|
165
|
-
return url;
|
|
166
|
-
}
|
|
126
|
+
Dipper.prototype.urlTo = function (route) {
|
|
127
|
+
if (/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(route)) return route;
|
|
128
|
+
return '/' + route.replace(/^\/+/, '');
|
|
129
|
+
};
|
|
167
130
|
|
|
168
131
|
Dipper.prototype.registerStyle = function(
|
|
169
132
|
name, url, requires,
|
package/framework/router.js
CHANGED
|
@@ -52,10 +52,13 @@ class Router {
|
|
|
52
52
|
|
|
53
53
|
addRoute(method, route, handler, insert) {
|
|
54
54
|
|
|
55
|
-
var obj = this,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
var obj = this,
|
|
56
|
+
insert = insert || false,
|
|
57
|
+
method = method.toLowerCase(),
|
|
58
|
+
instance = {
|
|
59
|
+
regexp: obj.routeToRegExp(route),
|
|
60
|
+
handler: handler
|
|
61
|
+
};
|
|
59
62
|
// Add the route, may be at the beginning or at the end
|
|
60
63
|
if (insert) { // Adding the route at the beginning of the route's array
|
|
61
64
|
obj.routes[method].unshift(instance);
|
|
@@ -71,9 +74,7 @@ class Router {
|
|
|
71
74
|
let response = new Response(res);
|
|
72
75
|
let request = new Request(req, {
|
|
73
76
|
onDataReceived: function () {
|
|
74
|
-
if (request.path == obj.
|
|
75
|
-
request.path = obj.server.options.base_url + obj.defaultRoute;
|
|
76
|
-
}
|
|
77
|
+
if (request.path == '') { request.path = obj.defaultRoute; }
|
|
77
78
|
// -- Check GET or POST routes
|
|
78
79
|
_.each(obj.routes[request.type], function (route) {
|
|
79
80
|
if (request.path.match(route.regexp)) {
|
|
@@ -104,7 +105,7 @@ class Router {
|
|
|
104
105
|
if (extHandled) {
|
|
105
106
|
|
|
106
107
|
let rep = obj.cwd.replace('core/framework', ''),
|
|
107
|
-
route = request.path
|
|
108
|
+
route = request.path,
|
|
108
109
|
filename = path.join(rep, route),
|
|
109
110
|
filePrivate = obj.isProtectedFile(route);
|
|
110
111
|
|
|
@@ -172,10 +173,7 @@ class Router {
|
|
|
172
173
|
}
|
|
173
174
|
|
|
174
175
|
getDefaultRoute() {
|
|
175
|
-
|
|
176
|
-
let obj = this,
|
|
177
|
-
prev = (obj.server.options.base_url && obj.server.options.base_url != '' && obj.server.options.base_url != '/') ? obj.server.options.base_url : '';
|
|
178
|
-
return (prev + obj.defaultRoute);
|
|
176
|
+
return this.defaultRoute;
|
|
179
177
|
}
|
|
180
178
|
|
|
181
179
|
onNotFound(response) {
|
package/framework/server.js
CHANGED
|
@@ -7,7 +7,6 @@ const path = require('path');
|
|
|
7
7
|
|
|
8
8
|
let Router = require('./router.js');
|
|
9
9
|
let Dipper = require('./dipper.js');
|
|
10
|
-
let Functions = require('./functions.js');
|
|
11
10
|
|
|
12
11
|
class Server {
|
|
13
12
|
|
|
@@ -31,10 +30,8 @@ class Server {
|
|
|
31
30
|
security = settings['security'] || {};
|
|
32
31
|
|
|
33
32
|
_.defaults(opts, {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
wsServer: false,
|
|
37
|
-
onNotFound: obj.onNotFound
|
|
33
|
+
https_server: false,
|
|
34
|
+
wsServer: false
|
|
38
35
|
});
|
|
39
36
|
obj.options = opts;
|
|
40
37
|
|
|
@@ -57,9 +54,6 @@ class Server {
|
|
|
57
54
|
// -- Create the server
|
|
58
55
|
obj.createServer();
|
|
59
56
|
|
|
60
|
-
// -- Not found callback
|
|
61
|
-
obj.onNotFound = opts.onNotFound;
|
|
62
|
-
|
|
63
57
|
// Initialize router
|
|
64
58
|
obj.router = new Router(obj);
|
|
65
59
|
|
|
@@ -69,56 +63,35 @@ class Server {
|
|
|
69
63
|
endpoints_built[endpoint.name] = new endpoint(obj.router);
|
|
70
64
|
}
|
|
71
65
|
this.endpoints = endpoints_built;
|
|
72
|
-
|
|
73
|
-
// Setting endpoints
|
|
74
|
-
obj.functions = new Functions();
|
|
75
66
|
}
|
|
76
67
|
|
|
77
68
|
start() {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// Listen on the specified port
|
|
83
|
-
obj.httpx.listen(port);
|
|
84
|
-
|
|
85
|
-
// Logging
|
|
86
|
-
obj.log('__________________ VanillaJet server started ___________________');
|
|
87
|
-
obj.log(` > Listening on ${obj.options.site_url}:${obj.options.port}${obj.options.base_url} < `);
|
|
88
|
-
obj.log('-----------------------------------------------------------------');
|
|
69
|
+
this.log('__________________ VanillaJet Server started ___________________');
|
|
70
|
+
this.log(` > Running on 0.0.0.0:${this.options.port}/ < `);
|
|
71
|
+
this.log('------------------------------------------------------------------');
|
|
89
72
|
}
|
|
90
73
|
|
|
91
74
|
createServer() {
|
|
92
75
|
|
|
93
76
|
let obj = this;
|
|
94
|
-
// -- Http server
|
|
95
|
-
let isLocalhost = /^((http):\/\/)/.test(obj.options.site_url) || /^((localhost))/.test(obj.options.site_url);
|
|
96
|
-
if (isLocalhost) {
|
|
97
|
-
obj.httpx = http.createServer((req, res) => {
|
|
98
|
-
obj.router.onRequest.call(obj.router, req, res);
|
|
99
|
-
});
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
77
|
|
|
103
78
|
// -- Https server (self managed certs)
|
|
104
79
|
if (obj.security.self_managed_certs) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
cert: fs.readFileSync(obj.security.cert, 'utf8'),
|
|
108
|
-
allowHTTP1: true
|
|
109
|
-
};
|
|
80
|
+
console.log('HTTPs server created - Self managed certs');
|
|
81
|
+
let certs = obj.getCertificates();
|
|
110
82
|
obj.httpx = http2.createSecureServer(certs, (req, res) => {
|
|
111
83
|
obj.router.onRequest.call(obj.router, req, res);
|
|
112
84
|
});
|
|
113
|
-
|
|
85
|
+
} else {
|
|
86
|
+
console.log('HTTP server created - Without self managed certs');
|
|
87
|
+
obj.httpx = http.createServer((req, res) => {
|
|
88
|
+
console.log('Request received: ', req.url);
|
|
89
|
+
obj.router.onRequest.call(obj.router, req, res);
|
|
90
|
+
});
|
|
114
91
|
}
|
|
115
|
-
|
|
116
|
-
// --
|
|
117
|
-
|
|
118
|
-
obj.httpx = http.createServer((req, res) => {
|
|
119
|
-
console.log('Request received: ', req.url);
|
|
120
|
-
obj.router.onRequest.call(obj.router, req, res);
|
|
121
|
-
});
|
|
92
|
+
|
|
93
|
+
// -- Set the port
|
|
94
|
+
obj.httpx.listen(obj.options.port || 8080);
|
|
122
95
|
}
|
|
123
96
|
|
|
124
97
|
log(value) {
|
|
@@ -129,11 +102,15 @@ class Server {
|
|
|
129
102
|
}
|
|
130
103
|
}
|
|
131
104
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
105
|
+
getCertificates() {
|
|
106
|
+
|
|
107
|
+
let obj = this;
|
|
108
|
+
return {
|
|
109
|
+
key: fs.readFileSync(obj.security.key, 'utf8'),
|
|
110
|
+
cert: fs.readFileSync(obj.security.cert, 'utf8'),
|
|
111
|
+
allowHTTP1: true
|
|
112
|
+
}
|
|
113
|
+
}
|
|
137
114
|
}
|
|
138
115
|
|
|
139
116
|
module.exports = Server;
|