vanilla-jet 1.0.41 → 1.1.0

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.
@@ -18,7 +18,7 @@ jobs:
18
18
  - name: Setup Node.js
19
19
  uses: actions/setup-node@v3
20
20
  with:
21
- node-version: '16'
21
+ node-version: '22'
22
22
  registry-url: 'https://registry.npmjs.org/'
23
23
 
24
24
  - name: Install dependencies
@@ -8,10 +8,10 @@ async function main() {
8
8
  // -- Create the object to be write in the file
9
9
  const json = {
10
10
  coreDependencies: {
11
- "modernizr": "//cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js",
12
- "respond": "//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js",
13
- "jquery": "//cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js",
14
- "underscore": "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.6/underscore-min.js"
11
+ "modernizr": "//cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js",
12
+ "respond": "//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js",
13
+ "jquery": "//cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js",
14
+ "underscore": "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.6/underscore-min.js"
15
15
  },
16
16
  dependencies: {},
17
17
  styles: {},
@@ -32,90 +32,70 @@ function Dipper(options, shared) {
32
32
  this.anims = [];
33
33
  this.enqueued_scripts = [];
34
34
  this.enqueued_styles = [];
35
-
36
- // -- Base scripts
37
- let vanillaJetJson = this.openJsonFile('vanillaJet.package.json');
38
- if (vanillaJetJson) {
39
- let coreDependencies = vanillaJetJson.coreDependencies;
40
- for (let key in coreDependencies) {
41
- this.registerScript(key, coreDependencies[key]);
42
- }
43
- }
44
35
  }
45
36
 
46
37
  Dipper.prototype.getPageTitle = function() {
47
-
48
- var obj = this;
38
+ let obj = this;
49
39
  return obj.site_title;
50
40
  }
51
41
 
52
42
  Dipper.prototype.getSiteTitle = function() {
53
-
54
- var obj = this;
43
+ let obj = this;
55
44
  return obj.page_title;
56
45
  }
57
46
 
58
47
  Dipper.prototype.getDescription = function() {
59
-
60
- var obj = this;
48
+ let obj = this;
61
49
  return obj.description;
62
50
  }
63
51
 
64
52
  Dipper.prototype.getFbAppId = function() {
65
-
66
- var obj = this;
53
+ let obj = this;
67
54
  return obj.fbAppId;
68
55
  }
69
56
 
70
57
  Dipper.prototype.addMeta = function(name, content, attribute) {
71
58
 
72
- var obj = this;
59
+ let obj = this;
73
60
  attribute = attribute || 'name';
74
61
  content = content || '';
75
- var meta = [];
76
- meta['name'] = name;
77
- meta['content'] = content;
78
- meta['attribute'] = attribute;
62
+ let meta = { 'name': name, 'content': content, 'attribute': attribute };
79
63
  obj.metas[name] = meta;
80
64
  }
81
65
 
82
66
  Dipper.prototype.metaTags = function() {
83
67
 
84
- var obj = this;
85
- var _ = require('underscore');
86
- var stringMeta = '';
68
+ let obj = this;
69
+ let _ = require('underscore');
70
+ let stringMeta = '';
87
71
 
88
- var keys = Object.keys(obj.metas);
72
+ let keys = Object.keys(obj.metas);
89
73
  _.each(keys, function(key) {
90
74
 
91
- var name = obj.metas[key]['name'],
75
+ let name = obj.metas[key]['name'],
92
76
  content = obj.metas[key]['content'],
93
77
  attribute = obj.metas[key]['attribute'];
94
78
 
95
79
  stringMeta += obj.metas[key]['content'] != '' ?
96
- '<meta ' + attribute + '=\"' + name + '\" content=\"' + content + '\">\n\t' :
97
- '<meta ' + attribute + '=\"' + name + '\">\n\t';
80
+ '<meta ' + attribute + '="' + name + '" content="' + content + '">\n\t' :
81
+ '<meta ' + attribute + '="' + name + '">\n\t';
98
82
  });
99
83
  return stringMeta;
100
84
  }
101
85
 
102
86
  Dipper.prototype.img = function(filename) {
103
87
 
104
- var obj = this,
105
- dir = this.getDir('images', false);
106
- ret = this.urlTo(dir + filename);
88
+ let dir = this.getDir('images', false);
89
+ let ret = this.urlTo(dir + filename);
107
90
  return ret;
108
91
  }
109
92
 
110
93
  Dipper.prototype.script = function(filename) {
111
94
 
112
- var obj = this,
113
- dir = this.getDir('scripts', false);
114
-
115
- var filenameParts = filename.split('.'),
95
+ let dir = this.getDir('scripts', false);
96
+ let filenameParts = filename.split('.'),
116
97
  length = filenameParts.length;
117
98
  if (length > 0) {
118
-
119
99
  let position = length - 1;
120
100
  filenameParts[position] = 'min.' + filenameParts[position];
121
101
  filename = filenameParts.join('.');
@@ -125,26 +105,22 @@ Dipper.prototype.script = function(filename) {
125
105
 
126
106
  Dipper.prototype.style = function(filename) {
127
107
 
128
- var obj = this,
129
- dir = this.getDir('styles', false),
130
- ret = this.urlTo(dir + filename);
108
+ let dir = this.getDir('styles', false);
109
+ let ret = this.urlTo(dir + filename);
131
110
  return ret;
132
111
  }
133
112
 
134
113
  Dipper.prototype.pdf = function(filename) {
135
114
 
136
- var obj = this,
137
- dir = '/assets/pdf/'
138
- ret = this.urlTo(dir + filename);
139
- //console.log(ret);
115
+ let dir = '/assets/pdf/';
116
+ let ret = this.urlTo(dir + filename);
140
117
  return ret;
141
118
  }
142
119
 
143
120
  Dipper.prototype.getDir = function(dir, full) {
144
121
 
145
- var obj = this,
146
- full = (full == undefined) ? true : full;
147
-
122
+ let obj = this;
123
+ full = (full == undefined) ? true : full;
148
124
  if ( obj.dirs[dir] != undefined ) {
149
125
  return (full == true ? obj.baseDir(obj.dirs[dir]) : obj.dirs[dir]);
150
126
  }
@@ -153,16 +129,14 @@ Dipper.prototype.getDir = function(dir, full) {
153
129
 
154
130
  Dipper.prototype.baseDir = function(path) {
155
131
 
156
- var obj = this,
157
- path = path || '',
158
- ret = obj.base_dir + path;
159
- return ret;
132
+ let obj = this;
133
+ path = path || '';
134
+ return obj.base_dir + path;
160
135
  }
161
136
 
162
137
  Dipper.prototype.isSecureRequest = function() {
163
138
 
164
- var obj = this;
165
- // Cheking for http or https
139
+ let obj = this;
166
140
  if (/^((http):\/\/)/.test(obj.options.site_url) || /^((localhost))/.test(obj.options.site_url)) {
167
141
  return false;
168
142
  } else if (/^((https):\/\/)/.test(obj.options.site_url)) {
@@ -172,11 +146,8 @@ Dipper.prototype.isSecureRequest = function() {
172
146
 
173
147
  Dipper.prototype.urlTo = function(route, protocol) {
174
148
 
175
- var obj = this,
176
- protocol = protocol || undefined,
177
- url = obj.base_url + route;
178
- //url = obj.baseUrl(route, protocol);
179
- return url;
149
+ let obj = this;
150
+ return obj.base_url + route;
180
151
  }
181
152
 
182
153
  Dipper.prototype.registerStyle = function(
@@ -184,7 +155,7 @@ Dipper.prototype.registerStyle = function(
184
155
  cdn = false, async = false,
185
156
  origin = '', integrity = '') {
186
157
 
187
- var obj = this;
158
+ let obj = this;
188
159
  obj.styles[name] = {
189
160
  'resource' : url,
190
161
  'requires' : requires,
@@ -200,7 +171,7 @@ Dipper.prototype.registerScript = function(
200
171
  cdn = false, async = false, defer = false,
201
172
  origin = '', integrity = '') {
202
173
 
203
- var obj = this;
174
+ let obj = this;
204
175
  obj.scripts[name] = {
205
176
 
206
177
  'resource' : url,
@@ -224,13 +195,13 @@ Dipper.prototype.registerAnimation = function(name, url) {
224
195
 
225
196
  Dipper.prototype.enqueueStyle = function(name) {
226
197
 
227
- var obj = this,
198
+ let obj = this,
228
199
  _ = require('underscore');
229
200
 
230
201
  if (obj.styles[name] != undefined) {
231
202
  if (obj.enqueued_styles[name] == undefined) {
232
203
 
233
- var item = obj.styles[name];
204
+ let item = obj.styles[name];
234
205
  _.each(item.requires, function(dep) {
235
206
  obj.enqueueStyle(dep);
236
207
  });
@@ -241,13 +212,13 @@ Dipper.prototype.enqueueStyle = function(name) {
241
212
 
242
213
  Dipper.prototype.enqueueScript = function(name) {
243
214
 
244
- var obj = this,
215
+ let obj = this,
245
216
  _ = require('underscore');
246
217
 
247
218
  if (obj.scripts[name] != undefined) {
248
219
  if (obj.enqueued_scripts[name] == undefined) {
249
220
 
250
- var item = obj.scripts[name];
221
+ let item = obj.scripts[name];
251
222
  _.each(item.requires, function(dep) {
252
223
  obj.enqueueScript(dep);
253
224
  });
@@ -258,13 +229,13 @@ Dipper.prototype.enqueueScript = function(name) {
258
229
 
259
230
  Dipper.prototype.dequeueStyle = function(name, dependencies) {
260
231
 
261
- var obj = this,
232
+ let obj = this,
262
233
  _ = require('underscore')
263
234
  dependencies = (dependencies == undefined) ? false : dependencies;
264
235
 
265
236
  if (obj.styles[name] != undefined) {
266
237
  if (obj.enqueued_styles[name] != undefined) {
267
- var item = obj.styles[name];
238
+ let item = obj.styles[name];
268
239
  if (dependencies != undefined) {
269
240
  _.each(item.require, function(dep) {
270
241
  obj.dequeueStyle(dep);
@@ -277,13 +248,13 @@ Dipper.prototype.dequeueStyle = function(name, dependencies) {
277
248
 
278
249
  Dipper.prototype.dequeueScript = function(name, dependencies) {
279
250
 
280
- var obj = this,
251
+ let obj = this,
281
252
  _ = require('underscore')
282
253
  dependencies = (dependencies == undefined) ? false : dependencies;
283
254
 
284
255
  if (obj.scripts[name] != undefined) {
285
256
  if (obj.enqueued_scripts[name] != undefined) {
286
- var item = obj.scripts[name];
257
+ let item = obj.scripts[name];
287
258
  if (dependencies != undefined) {
288
259
  _.each(item.require, function(dep) {
289
260
  obj.dequeueScript(dep);
@@ -296,23 +267,23 @@ Dipper.prototype.dequeueScript = function(name, dependencies) {
296
267
 
297
268
  Dipper.prototype.includeStyle = function(style) {
298
269
 
299
- var obj = this;
270
+ let obj = this;
300
271
  if (obj.styles[style]) {
301
272
 
302
- var item = obj.styles[style],
273
+ let item = obj.styles[style],
303
274
  output = '',
304
275
  //type = item['cdn'] ? "" : 'type=\"text/javascript\"',
305
276
  resource = item['resource'],
306
277
  isAsync = item['async'] ? 'preload' : 'stylesheet',
307
- origin = item['origin'] != '' ? ' crossorigin=\"' + item['origin'] + '\"' : '',
308
- integrity = item['integrity'] != '' ? ' integrity=\"' + item['integrity'] + '\"' : '';
278
+ origin = item['origin'] != '' ? ' crossorigin="' + item['origin'] + '"' : '',
279
+ integrity = item['integrity'] != '' ? ' integrity="' + item['integrity'] + '"' : '';
309
280
 
310
281
  if (item['async']) {
311
282
 
312
- var a = " as=\"style\" onload=\"this.onload=null; this.rel='stylesheet'\"";
313
- output = '<link rel=\"' + isAsync + '\" type=\"text/css\" href=\"' + resource + '\"' + a + integrity + origin + ">";
283
+ let a = " as=\"style\" onload=\"this.onload=null; this.rel='stylesheet'\"";
284
+ output = '<link rel="' + isAsync + '" type="text/css" href="' + resource + '"' + a + integrity + origin + ">";
314
285
  } else {
315
- output = '<link rel=\"' + isAsync + '\" type=\"text/css\" href=\"' + resource + '\"' + integrity + origin + ">";
286
+ output = '<link rel="' + isAsync + '" type="text/css" href="' + resource + '"' + integrity + origin + ">";
316
287
  }
317
288
  return output + "\n";
318
289
  }
@@ -320,20 +291,19 @@ Dipper.prototype.includeStyle = function(style) {
320
291
 
321
292
  Dipper.prototype.includeScript = function(script) {
322
293
 
323
- var obj = this;
294
+ let obj = this;
324
295
  if (obj.scripts[script]) {
325
296
 
326
- var item = obj.scripts[script],
297
+ let item = obj.scripts[script],
327
298
  output = '',
328
299
  //type = item['cdn'] ? "" : 'type=\"text/javascript\"',
329
300
  resource = item['resource'],
330
301
  isAsync = item['async'] ? ' async' : '',
331
302
  defer = item['defer'] ? ' defer' : '',
332
- origin = item['origin'] != '' ? ' crossorigin=\"' + item['origin'] + '\"' : '',
333
- integrity = item['integrity'] != '' ? ' integrity=\"' + item['integrity'] + '\"' : '';
303
+ origin = item['origin'] != '' ? ' crossorigin="' + item['origin'] + '"' : '',
304
+ integrity = item['integrity'] != '' ? ' integrity="' + item['integrity'] + '"' : '';
334
305
 
335
- output = '<script src=\"' + resource + '\"' + defer + isAsync + integrity + origin + '></script>';
336
- //console.log(output);
306
+ output = '<script src="' + resource + '"' + defer + isAsync + integrity + origin + '></script>';
337
307
  return output + "\n";
338
308
  }
339
309
  }
@@ -357,25 +327,22 @@ Dipper.prototype.includeAnimation = function(anim) {
357
327
 
358
328
  Dipper.prototype.includeStyles = function() {
359
329
 
360
- var obj = this,
361
- _ = require('underscore')
362
- stylesString = '',
330
+ let obj = this,
331
+ _ = require('underscore');
332
+ let stylesString = '',
363
333
  keys = Object.keys(obj.enqueued_styles);
364
334
 
365
335
  _.each(keys, function(style) {
366
336
  stylesString += obj.includeStyle(style);
367
337
  });
368
-
369
- //console.log(stylesString);
370
- //$site->executeHook('core.includeStyles');
371
338
  return stylesString;
372
339
  }
373
340
 
374
341
  Dipper.prototype.includeScripts = function () {
375
342
 
376
- var obj = this,
343
+ let obj = this,
377
344
  _ = require('underscore')
378
- scriptsString = '',
345
+ let scriptsString = '',
379
346
  keys = Object.keys(obj.enqueued_scripts);
380
347
 
381
348
  _.each(keys, function(script) {
@@ -400,9 +367,9 @@ Dipper.prototype.includeAnimations = function() {
400
367
 
401
368
  Dipper.prototype.includeManifest = function() {
402
369
 
403
- var obj = this,
370
+ let obj = this,
404
371
  url = obj.urlTo('/public/manifest.json'),
405
- tagString = '<link rel=\"manifest\" href=\"' + url + '\">';
372
+ tagString = '<link rel="manifest" href="' + url + '">';
406
373
  return tagString;
407
374
  }
408
375
 
@@ -2,98 +2,103 @@ class Functions {
2
2
 
3
3
  constructor() {
4
4
 
5
- // Dipper
6
- dipper = global.dipper;
5
+ // Dipper
6
+ dipper = global.dipper;
7
7
 
8
- // -- Hydrate
9
- Functions.hydrate(dipper);
8
+ // -- Hydrate
9
+ Functions.hydrate(dipper);
10
10
  }
11
11
 
12
12
  static hydrate(dipper) {
13
13
 
14
- // -- Get vanillaJet.package.json
15
- let json = dipper.openJsonFile('vanillaJet.package.json');
16
-
17
- // -- Google Fonts
18
- if (json.fonts && json.fonts.length > 0) {
19
- dipper.registerStyle('google-fonts', dipper.get_google_fonts(json.fonts));
20
- }
21
-
22
- // - Styles
23
- let stylesKeys = [];
24
- if (json.styles) {
25
-
26
- // -- Gettign the keys
27
- stylesKeys = Object.keys(json.styles);
28
-
29
- // -- Add google-fonts to keys
30
- stylesKeys.push('google-fonts');
31
-
32
- // -- Adding styles
33
- for (let key in json.styles) {
34
- // -- Check if init with http or https
35
- let url = json.styles[key];
36
- if (!/^(https?:\/\/|\/\/)/.test(url)) {
37
- dipper.registerStyle(key, dipper.style(url));
38
- } else {
39
- dipper.registerStyle(key, url);
40
- }
41
- }
14
+ // -- Get vanillaJet.package.json
15
+ let json = dipper.openJsonFile('vanillaJet.package.json');
16
+
17
+ // -- Google Fonts
18
+ if (json.fonts && json.fonts.length > 0) {
19
+ dipper.registerStyle('google-fonts', dipper.get_google_fonts(json.fonts));
20
+ }
21
+
22
+ // - Styles
23
+ let stylesKeys = [];
24
+ if (json.styles) {
25
+
26
+ // -- Gettign the keys
27
+ stylesKeys = Object.keys(json.styles);
28
+
29
+ // -- Add google-fonts to keys
30
+ stylesKeys.push('google-fonts');
31
+
32
+ // -- Adding styles
33
+ for (let key in json.styles) {
34
+ // -- Check if init with http or https
35
+ let url = json.styles[key];
36
+ if (!/^(https?:\/\/|\/\/)/.test(url)) {
37
+ dipper.registerStyle(key, dipper.style(url));
38
+ } else {
39
+ dipper.registerStyle(key, url);
40
+ }
42
41
  }
43
- dipper.registerStyle('app', dipper.style('app.min.css'), stylesKeys);
44
- dipper.enqueueStyle('app');
45
-
46
- // -- Scripts
47
- let scriptsKeys = [];
48
- if (json.dependencies) {
49
-
50
- // -- Adding scripts
51
- for (let key in json.dependencies) {
52
-
53
- // -- Key name and requires
54
- let keyParts = key.split(':');
55
- let keyName = keyParts[0];
56
- let keyRequires = keyParts[1] || '';
57
-
58
- // -- Add key to scriptsKeys
59
- scriptsKeys.push(keyName);
60
-
61
- // -- Check if init with http or https
62
- let url = json.dependencies[key];
63
- if (!/^(https?:\/\/|\/\/)/.test(url)) {
64
- dipper.registerScript(
65
- keyName,
66
- dipper.script(url),
67
- (keyRequires !== '') ? [keyRequires] : undefined
68
- );
69
- } else {
70
- dipper.registerScript(
71
- keyName,
72
- url,
73
- (keyRequires !== '') ? [keyRequires] : undefined
74
- );
75
- }
76
- }
42
+ }
43
+ dipper.registerStyle('app', dipper.style('app.min.css'), stylesKeys);
44
+ dipper.enqueueStyle('app');
45
+
46
+ // -- Core dependencies - Base scripts
47
+ for (let key in json.coreDependencies) {
48
+ dipper.registerScript(key, json.coreDependencies[key]);
49
+ }
50
+
51
+ // -- Scripts
52
+ let scriptsKeys = [];
53
+ if (json.dependencies) {
54
+
55
+ // -- Adding scripts
56
+ for (let key in json.dependencies) {
57
+
58
+ // -- Key name and requires
59
+ let keyParts = key.split(':');
60
+ let keyName = keyParts[0];
61
+ let keyRequires = keyParts[1] || '';
62
+
63
+ // -- Add key to scriptsKeys
64
+ scriptsKeys.push(keyName);
65
+
66
+ // -- Check if init with http or https
67
+ let url = json.dependencies[key];
68
+ if (!/^(https?:\/\/|\/\/)/.test(url)) {
69
+ dipper.registerScript(
70
+ keyName,
71
+ dipper.script(url),
72
+ (keyRequires !== '') ? [keyRequires] : undefined
73
+ );
74
+ } else {
75
+ dipper.registerScript(
76
+ keyName,
77
+ url,
78
+ (keyRequires !== '') ? [keyRequires] : undefined
79
+ );
80
+ }
77
81
  }
78
- scriptsKeys.push('jquery');
79
- scriptsKeys.push('underscore');
80
- dipper.registerScript('vanillaJet', dipper.script('core/vanillaJet.js'), scriptsKeys);
81
- dipper.enqueueScript('vanillaJet');
82
-
83
- // -- Main app
84
- dipper.registerScript('vanilla', dipper.script('vanilla.js'));
85
- dipper.enqueueScript('vanilla');
86
-
87
- // Adding meta tags
88
- dipper.addMeta('UTF-8', '', 'charset');
89
- dipper.addMeta('viewport', 'width=device-width, minimum-scale=1');
90
- dipper.addMeta('og:title', dipper.getPageTitle(), 'property');
91
- dipper.addMeta('og:site_name', dipper.getSiteTitle(), 'property');
92
- dipper.addMeta('og:description', dipper.getDescription(), 'property');
93
- dipper.addMeta('og:image', dipper.img('logo.png'), 'property');
94
- dipper.addMeta('og:type', 'website', 'property');
95
- dipper.addMeta('og:url', dipper.urlTo(''), 'property');
96
- dipper.addMeta('theme-color', '#ffffff', '');
82
+ }
83
+ /*scriptsKeys.push('jquery');
84
+ scriptsKeys.push('underscore');
85
+ dipper.registerScript('vanillaJet', dipper.script('core/vanillaJet.js'), scriptsKeys);
86
+ dipper.enqueueScript('vanillaJet');*/
87
+
88
+ // -- Main app
89
+ dipper.registerScript('vanilla', dipper.script('vanilla.js'));
90
+ dipper.enqueueScript('vanilla');
91
+
92
+ // Adding meta tags
93
+ dipper.addMeta('UTF-8', '', 'charset');
94
+ dipper.addMeta('viewport', 'width=device-width, minimum-scale=1');
95
+ dipper.addMeta('og:title', dipper.getPageTitle(), 'property');
96
+ dipper.addMeta('og:site_name', dipper.getSiteTitle(), 'property');
97
+ dipper.addMeta('og:description', dipper.getDescription(), 'property');
98
+ dipper.addMeta('og:image', dipper.img('logo.png'), 'property');
99
+ dipper.addMeta('og:type', 'website', 'property');
100
+ dipper.addMeta('og:url', dipper.urlTo(''), 'property');
101
+ dipper.addMeta('theme-color', '#ffffff', '');
97
102
  }
98
103
  }
99
104
 
@@ -22,7 +22,10 @@ class Request {
22
22
 
23
23
  init(req, options) {
24
24
 
25
- var obj = this, body = '', options = options || {}, parsed = url.parse(req.url, true);
25
+ let obj = this,
26
+ body = '',
27
+ parsed = url.parse(req.url, true);
28
+ options = options || {};
26
29
 
27
30
  // Save callbacks
28
31
  obj.onDataReceived = options.onDataReceived || obj.onDataReceived;
@@ -43,7 +46,7 @@ class Request {
43
46
  }
44
47
 
45
48
  // Matches
46
- var matches = (obj.id == null) ? null : obj.id.match(/\.([a-z0-9]+)$/);
49
+ let matches = (obj.id == null) ? null : obj.id.match(/\.([a-z0-9]+)$/);
47
50
  if (matches) {
48
51
  obj.format = matches[1] || 'html';
49
52
  obj.id = obj.id.replace(/\.([a-z0-9]+)$/, '');
@@ -58,7 +61,7 @@ class Request {
58
61
  req.on('end', function (chunk) {
59
62
  obj.params.body = body;
60
63
  obj.params.post = querystring.parse(body);
61
- obj.onDataReceived.call(obj);
64
+ obj.onDataReceived(obj);
62
65
  });
63
66
  }
64
67
 
@@ -69,7 +72,8 @@ class Request {
69
72
  **/
70
73
  param(name, value) {
71
74
 
72
- var obj = this, ret = value || '';
75
+ let obj = this,
76
+ ret = value || '';
73
77
  // Try to retrieve parameter from both, POST and GET objects
74
78
  if (typeof obj.params.post[name] !== 'undefined') {
75
79
  ret = obj.params.post[name];
@@ -81,7 +85,8 @@ class Request {
81
85
 
82
86
  post(name, value) {
83
87
 
84
- var obj = this, ret = value || '';
88
+ let obj = this,
89
+ ret = value || '';
85
90
  // Try to retrieve parameter from POST object
86
91
  if (typeof obj.params.post[name] !== 'undefined') {
87
92
  ret = obj.params.post[name];
@@ -91,7 +96,8 @@ class Request {
91
96
 
92
97
  get(name, value) {
93
98
 
94
- var obj = this, ret = value || '';
99
+ let obj = this,
100
+ ret = value || '';
95
101
  // Try to retrieve parameter from GET object
96
102
  if (typeof obj.params.get[name] !== 'undefined') {
97
103
  ret = obj.params.get[name];
@@ -100,8 +106,7 @@ class Request {
100
106
  }
101
107
 
102
108
  body() {
103
-
104
- var obj = this;
109
+ let obj = this;
105
110
  return obj.params.body;
106
111
  }
107
112
  }
@@ -10,31 +10,26 @@ class Response {
10
10
  this.status = 200;
11
11
  this.headers = [];
12
12
  this.autoRespond = true;
13
- // Call initialization callback
14
13
  this.init(res);
15
14
  }
16
15
 
17
16
  init(res) {
18
-
19
- var obj = this;
17
+ let obj = this;
20
18
  obj.res = res;
21
19
  }
22
20
 
23
21
  setBody(body) {
24
-
25
- var obj = this;
22
+ let obj = this;
26
23
  obj.body = body;
27
24
  }
28
25
 
29
26
  setStatus(status) {
30
-
31
- var obj = this;
27
+ let obj = this;
32
28
  obj.status = status;
33
29
  }
34
30
 
35
31
  setHeader(name, value) {
36
-
37
- var obj = this;
32
+ let obj = this;
38
33
  obj.headers.push({
39
34
  name: name,
40
35
  value: value
@@ -42,20 +37,18 @@ class Response {
42
37
  }
43
38
 
44
39
  getBody() {
45
-
46
- var obj = this;
40
+ let obj = this;
47
41
  return obj.body;
48
42
  }
49
43
 
50
44
  getStatus() {
51
-
52
- var obj = this;
45
+ let obj = this;
53
46
  return obj.status;
54
47
  }
55
48
 
56
49
  getHeader(name) {
57
-
58
- var obj = this, ret = null;
50
+ let obj = this,
51
+ ret = null;
59
52
  ret = _.find(obj.headers, function (header) {
60
53
  return header.name == name;
61
54
  });
@@ -63,8 +56,7 @@ class Response {
63
56
  }
64
57
 
65
58
  respond() {
66
-
67
- var obj = this;
59
+ let obj = this;
68
60
  this.setHeader('Access-Control-Allow-Origin', '*');
69
61
 
70
62
  _.each(obj.headers, function (header) {
@@ -75,8 +67,7 @@ class Response {
75
67
  }
76
68
 
77
69
  error404() {
78
-
79
- var obj = this;
70
+ let obj = this;
80
71
  obj.res.writeHead(404, { "Content-Type": "text/plain" });
81
72
  obj.res.write("404 Not Found\n");
82
73
  obj.res.end();
@@ -84,7 +75,10 @@ class Response {
84
75
 
85
76
  render(template) {
86
77
 
87
- var obj = this, path = require("path"), fs = require("fs"), template = 'pages/' + template;
78
+ let obj = this,
79
+ path = require("path"),
80
+ fs = require("fs");
81
+ template = 'pages/' + template;
88
82
 
89
83
  const filename = path.join(process.cwd(), 'public/' + template);
90
84
  const fileStream = fs.createReadStream(filename);
@@ -18,8 +18,7 @@ class Router {
18
18
 
19
19
  routeToRegExp(route) {
20
20
 
21
- var optionalParam = /\((.*?)\)/g, namedParam = /(\(\?)?:\w+/g, splatParam = /\*\w+/g, escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g;
22
- // Convert route to regular expression, this was taken from Backbone's router
21
+ let optionalParam = /\((.*?)\)/g, namedParam = /(\(\?)?:\w+/g, splatParam = /\*\w+/g, escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g;
23
22
  route = route.replace(escapeRegExp, '\\$&')
24
23
  .replace(optionalParam, '(?:$1)?')
25
24
  .replace(namedParam, function (match, optional) {
@@ -31,20 +30,21 @@ class Router {
31
30
 
32
31
  addRoute(method, route, handler, insert) {
33
32
 
34
- var obj = this, insert = insert || false, method = method.toLowerCase(), prev = (obj.server.options.base_url && obj.server.options.base_url != '' && obj.server.options.base_url != '/') ? obj.server.options.base_url : '', instance = {
35
- regexp: obj.routeToRegExp(prev + route),
36
- handler: handler
37
- };
38
- // Add the route, may be at the beginning or at the end
39
- if (insert) { // Adding the route at the beginning of the route's array
33
+ let obj = this,
34
+ insert = insert || false,
35
+ method = method.toLowerCase(),
36
+ prev = (obj.server.options.base_url && obj.server.options.base_url != '' && obj.server.options.base_url != '/') ? obj.server.options.base_url : '',
37
+ instance = {
38
+ regexp: obj.routeToRegExp(prev + route),
39
+ handler: handler
40
+ };
41
+ if (insert) {
40
42
  obj.routes[method].unshift(instance);
41
- } else { // Adding the route at the end of the route's array
43
+ } else {
42
44
  obj.routes[method].push(instance);
43
45
  }
44
46
  }
45
47
 
46
- removeRoute(method, route) {}
47
-
48
48
  onRequest(req, res) {
49
49
 
50
50
  let obj = this;
@@ -54,19 +54,14 @@ class Router {
54
54
  let request = new Request(req, {
55
55
  onDataReceived: function () {
56
56
 
57
- //console.log(request.path);
58
57
  if (request.path == obj.server.options.base_url) {
59
58
  request.path = obj.server.options.base_url + obj.defaultRoute;
60
59
  }
61
- //console.log(request.path);
62
- // Try with the routes for the current method (get or post)
60
+ // -- Try with the routes for the current method (get or post)
63
61
  _.each(obj.routes[request.type], function (route) {
64
62
  if (request.path.match(route.regexp)) {
65
-
66
- var parts = route.handler.split('.'), clazz = parts[0], method = parts[1], callback = obj.validateCallback(clazz, method);
67
-
63
+ let parts = route.handler.split('.'), clazz = parts[0], method = parts[1], callback = obj.validateCallback(clazz, method);
68
64
  if (callback && callback != undefined && callback != '') {
69
-
70
65
  isMatch = true;
71
66
  handled = callback(request, response, obj.server);
72
67
  return;
@@ -77,13 +72,9 @@ class Router {
77
72
  // If not handled yet, try with the wildcard ones
78
73
  if (!handled) {
79
74
  _.each(obj.routes['*'], function (route) {
80
-
81
75
  if (request.path.match(route.regexp)) {
82
-
83
- var parts = route.handler.split('.'), clazz = parts[0], method = parts[1], callback = obj.validateCallback(clazz, method);
84
-
76
+ let parts = route.handler.split('.'), clazz = parts[0], method = parts[1], callback = obj.validateCallback(clazz, method);
85
77
  if (callback && callback != undefined && callback != '') {
86
-
87
78
  isMatch = true;
88
79
  handled = callback(request, response, obj.server);
89
80
  return;
@@ -96,8 +87,8 @@ class Router {
96
87
  // or not handled? Well, at this point we call 404
97
88
  if (handled == false && isMatch == false) {
98
89
 
99
- var path = require('path'), ext = path.extname(req.url).replace('.', ''), extHandled = false, extHeader = {};
100
- var mimes = {
90
+ let path = require('path'), ext = path.extname(req.url).replace('.', ''), extHandled = false, extHeader = {};
91
+ let mimes = {
101
92
  'png': 'image/png',
102
93
  'webp': 'image/webp',
103
94
  'jpg': 'image/jpg',
@@ -111,15 +102,13 @@ class Router {
111
102
  'pdf': 'application/pdf',
112
103
  'json': 'application/json'
113
104
  };
114
-
115
- var compressionMimes = {
105
+ let compressionMimes = {
116
106
  'css': 'text/css',
117
107
  'js': 'text/javascript',
118
108
  'gz': 'application/x-gzip'
119
109
  };
120
110
 
121
111
  if (mimes[ext] != undefined && mimes[ext] != 'undefined') {
122
-
123
112
  extHandled = true;
124
113
  extHeader = { 'Content-Type': mimes[ext] };
125
114
  }
@@ -133,12 +122,9 @@ class Router {
133
122
  filePrivate = obj.isProtectedFile(route);
134
123
 
135
124
  fs.exists(filename, function (exists) {
136
-
137
125
  if (exists && !filePrivate) {
138
-
139
- var acceptEncoding = (req.headers['accept-encoding'] != undefined) ? req.headers['accept-encoding'] : '';
140
- var fileStream = fs.createReadStream(filename);
141
-
126
+ let acceptEncoding = (req.headers['accept-encoding'] != undefined) ? req.headers['accept-encoding'] : '';
127
+ let fileStream = fs.createReadStream(filename);
142
128
  if (ext === 'js' && !route.match(/(vanilla\.min\.js|vanillaJet\.min\.js)$/)) {
143
129
  extHeader['Cache-Control'] = 'public, max-age=15552000';
144
130
  extHeader['Expires'] = new Date(Date.now() + 15552000000).toUTCString();
@@ -155,8 +141,6 @@ class Router {
155
141
  return;
156
142
 
157
143
  } else {
158
-
159
- // Return 404
160
144
  obj.onNotFound(response);
161
145
  }
162
146
  });
@@ -170,23 +154,20 @@ class Router {
170
154
  isProtectedFile(route) {
171
155
 
172
156
  let protectedDirs = ['framework', 'external', 'node_mudules'];
173
- var routeParts = route.split('/');
157
+ const routeParts = route.split('/');
174
158
  if (routeParts[1] != undefined && routeParts.length > 2) {
175
159
  return protectedDirs.includes(routeParts[1]);
176
160
  }
177
161
  return true;
178
162
  }
179
163
 
180
- validateExtension(route) {}
181
-
182
164
  validateCallback(clazz, method) {
183
165
 
184
- var obj = this, endpoints = obj.server.endpoints;
166
+ let obj = this,
167
+ endpoints = obj.server.endpoints;
185
168
 
186
169
  if (endpoints[clazz] != undefined) {
187
-
188
170
  clazz = endpoints[clazz];
189
-
190
171
  if (typeof clazz[method] === 'function') {
191
172
  return clazz[method];
192
173
  }
@@ -200,19 +181,17 @@ class Router {
200
181
  **/
201
182
  setDefaultRoute(route) {
202
183
 
203
- var obj = this;
184
+ let obj = this;
204
185
  obj.defaultRoute = route;
205
186
  }
206
187
 
207
188
  getDefaultRoute() {
208
-
209
- var obj = this, prev = (obj.server.options.base_url && obj.server.options.base_url != '' && obj.server.options.base_url != '/') ? obj.server.options.base_url : '';
210
-
189
+ let obj = this,
190
+ prev = (obj.server.options.base_url && obj.server.options.base_url != '' && obj.server.options.base_url != '/') ? obj.server.options.base_url : '';
211
191
  return (prev + obj.defaultRoute);
212
192
  }
213
193
 
214
194
  onNotFound(response) {
215
-
216
195
  response.setStatus(404);
217
196
  response.respond();
218
197
  }
@@ -41,6 +41,7 @@ class Server {
41
41
  _.defaults(security, {
42
42
  pass_salt: '1234567890',
43
43
  token_salt: '0987654321',
44
+ self_managed_certs: false,
44
45
  version: '1.0'
45
46
  });
46
47
  obj.security = security;
@@ -53,26 +54,10 @@ class Server {
53
54
  });
54
55
  global.dipper = new Dipper(opts, shared);
55
56
 
56
- // Cheking for http or https
57
- if (/^((http):\/\/)/.test(obj.options.site_url) || /^((localhost))/.test(obj.options.site_url)) {
58
-
59
- obj.httpx = http.createServer((req, res) => {
60
- //console.log(req.url);
61
- obj.router.onRequest.call(obj.router, req, res);
62
- });
63
-
64
- } else if (/^((https):\/\/)/.test(obj.options.site_url)) {
65
-
66
- let certs = {
67
- key: fs.readFileSync(obj.security.key, 'utf8'),
68
- cert: fs.readFileSync(obj.security.cert, 'utf8'),
69
- allowHTTP1: true
70
- };
71
- obj.httpx = http2.createSecureServer(certs, (req, res) => {
72
- obj.router.onRequest.call(obj.router, req, res);
73
- });
74
- }
57
+ // -- Create the server
58
+ obj.httpx = obj.createServer(obj.options, obj.security);
75
59
 
60
+ // -- On not found
76
61
  obj.onNotFound = opts.onNotFound;
77
62
 
78
63
  // Initialize router
@@ -89,6 +74,35 @@ class Server {
89
74
  obj.functions = new Functions();
90
75
  }
91
76
 
77
+ createServer(options, security) {
78
+
79
+ let obj = this;
80
+ // -- Http server
81
+ let isHttp = /^((http):\/\/)/.test(options.site_url) || /^((localhost))/.test(options.site_url);
82
+ if (isHttp) {
83
+ return http.createServer((req, res) => {
84
+ obj.router.onRequest(obj.router, req, res);
85
+ });
86
+ }
87
+
88
+ // -- Https server (self managed certs)
89
+ if (security.self_managed_certs) {
90
+ let certs = {
91
+ key: fs.readFileSync(security.key, 'utf8'),
92
+ cert: fs.readFileSync(security.cert, 'utf8'),
93
+ allowHTTP1: true
94
+ };
95
+ return http2.createSecureServer(certs, (req, res) => {
96
+ obj.router.onRequest(obj.router, req, res);
97
+ });
98
+ }
99
+
100
+ // -- Certs managed by NGINX, Google Cloud Run, etc.
101
+ return http2.createServer({ allowHTTP1: true }, (req, res) => {
102
+ obj.router.onRequest(obj.router, req, res);
103
+ });
104
+ }
105
+
92
106
  start() {
93
107
 
94
108
  let obj = this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vanilla-jet",
3
- "version": "1.0.41",
3
+ "version": "1.1.0",
4
4
  "description": "VannilaJet framework",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -29,26 +29,26 @@
29
29
  },
30
30
  "homepage": "https://github.com/nalancer08/VanillaJet#readme",
31
31
  "dependencies": {
32
- "blueimp-md5": "2.8.0",
33
- "chalk": "4.1.2",
32
+ "blueimp-md5": "2.19.0",
33
+ "chalk": "5.4.1",
34
34
  "grunt": "1.6.1",
35
- "grunt-cli": "1.4.3",
35
+ "grunt-cli": "1.5.0",
36
36
  "grunt-contrib-clean": "2.0.1",
37
37
  "grunt-contrib-compress": "2.0.0",
38
38
  "grunt-contrib-concat": "2.1.0",
39
39
  "grunt-contrib-cssmin": "5.0.0",
40
40
  "grunt-contrib-less": "3.0.0",
41
- "grunt-contrib-uglify": "5.0.1",
41
+ "grunt-contrib-uglify": "5.2.2",
42
42
  "grunt-contrib-watch": "1.1.0",
43
43
  "grunt-run": "0.8.1",
44
44
  "grunt-shell": "4.0.0",
45
45
  "html-minifier-terser": "7.2.0",
46
46
  "jit-grunt": "0.10.0",
47
- "js-beautify": "1.14.8",
48
- "jsrsasign": "11.0.0",
49
- "jwt-simple": "0.5.3",
50
- "minimist": "1.2.6",
51
- "nodemon": "3.0.1",
47
+ "js-beautify": "1.15.4",
48
+ "jsrsasign": "11.1.0",
49
+ "jwt-simple": "0.5.6",
50
+ "minimist": "1.2.8",
51
+ "nodemon": "3.1.10",
52
52
  "nunjucks": "3.2.4",
53
53
  "underscore": ">= 1.12.x",
54
54
  "zlib": "1.0.5"