vanilla-jet 1.0.5 → 1.0.7

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.
@@ -1,102 +1,96 @@
1
- /**
2
- Version 3.5
3
- Created by: nalancer08 <https://github.com/nalancer08>
4
- **/
5
-
6
1
  const nunjucks = require('nunjucks');
7
- var _ = require('underscore');
2
+ let _ = require('underscore');
8
3
 
9
- function Response(res) {
4
+ class Response {
10
5
 
11
- this.res = null;
12
- this.body = '';
13
- this.status = 200;
14
- this.headers = [];
15
- this.autoRespond = true;
16
- // Call initialization callback
17
- this.init(res);
18
- }
6
+ constructor(res) {
19
7
 
20
- Response.prototype.init = function(res) {
8
+ this.res = null;
9
+ this.body = '';
10
+ this.status = 200;
11
+ this.headers = [];
12
+ this.autoRespond = true;
13
+ // Call initialization callback
14
+ this.init(res);
15
+ }
21
16
 
22
- var obj = this;
23
- obj.res = res;
24
- }
17
+ init(res) {
25
18
 
26
- Response.prototype.setBody = function(body) {
19
+ var obj = this;
20
+ obj.res = res;
21
+ }
27
22
 
28
- var obj = this;
29
- obj.body = body;
30
- }
23
+ setBody(body) {
31
24
 
32
- Response.prototype.setStatus = function(status) {
25
+ var obj = this;
26
+ obj.body = body;
27
+ }
33
28
 
34
- var obj = this;
35
- obj.status = status;
36
- }
29
+ setStatus(status) {
37
30
 
38
- Response.prototype.setHeader = function(name, value) {
31
+ var obj = this;
32
+ obj.status = status;
33
+ }
39
34
 
40
- var obj = this;
41
- obj.headers.push({
42
- name: name,
43
- value: value
44
- });
45
- }
35
+ setHeader(name, value) {
46
36
 
47
- Response.prototype.getBody = function() {
37
+ var obj = this;
38
+ obj.headers.push({
39
+ name: name,
40
+ value: value
41
+ });
42
+ }
48
43
 
49
- var obj = this;
50
- return obj.body;
51
- }
44
+ getBody() {
52
45
 
53
- Response.prototype.getStatus = function() {
46
+ var obj = this;
47
+ return obj.body;
48
+ }
54
49
 
55
- var obj = this;
56
- return obj.status;
57
- }
50
+ getStatus() {
58
51
 
59
- Response.prototype.getHeader = function(name) {
52
+ var obj = this;
53
+ return obj.status;
54
+ }
60
55
 
61
- var obj = this,
62
- ret = null;
63
- ret = _.find(obj.headers, function(header) {
64
- return header.name == name;
65
- });
66
- return ret;
67
- }
56
+ getHeader(name) {
68
57
 
69
- Response.prototype.respond = function() {
58
+ var obj = this, ret = null;
59
+ ret = _.find(obj.headers, function (header) {
60
+ return header.name == name;
61
+ });
62
+ return ret;
63
+ }
70
64
 
71
- var obj = this;
72
- this.setHeader('Access-Control-Allow-Origin', '*');
65
+ respond() {
73
66
 
74
- _.each(obj.headers, function(header) {
75
- obj.res.setHeader(header.name, header.value);
76
- });
77
- obj.res.writeHead(obj.status);
78
- obj.res.end(obj.body);
79
- }
67
+ var obj = this;
68
+ this.setHeader('Access-Control-Allow-Origin', '*');
80
69
 
81
- Response.prototype.error404 = function() {
70
+ _.each(obj.headers, function (header) {
71
+ obj.res.setHeader(header.name, header.value);
72
+ });
73
+ obj.res.writeHead(obj.status);
74
+ obj.res.end(obj.body);
75
+ }
82
76
 
83
- var obj = this;
84
- obj.res.writeHead(404, {"Content-Type": "text/plain"});
85
- obj.res.write("404 Not Found\n");
86
- obj.res.end();
87
- }
77
+ error404() {
78
+
79
+ var obj = this;
80
+ obj.res.writeHead(404, { "Content-Type": "text/plain" });
81
+ obj.res.write("404 Not Found\n");
82
+ obj.res.end();
83
+ }
88
84
 
89
- Response.prototype.render = function(template) {
85
+ render(template) {
90
86
 
91
- var obj = this,
92
- path = require("path"),
93
- fs = require("fs"),
94
- template = 'pages/' + template;
87
+ var obj = this, path = require("path"), fs = require("fs"), template = 'pages/' + template;
95
88
 
96
- const filename = path.join(process.cwd(), 'public/' + template);
97
- const fileStream = fs.createReadStream(filename);
98
- obj.res.writeHead(200, { 'Content-Type': 'text/html' });
99
- fileStream.pipe(obj.res);
89
+ const filename = path.join(process.cwd(), 'public/' + template);
90
+ const fileStream = fs.createReadStream(filename);
91
+ obj.res.writeHead(200, { 'Content-Type': 'text/html' });
92
+ fileStream.pipe(obj.res);
93
+ }
100
94
  }
101
95
 
102
- module.exports = Response;
96
+ module.exports = Response;
@@ -126,7 +126,11 @@ class Router {
126
126
 
127
127
  if (extHandled) {
128
128
 
129
- let fs = require('fs'), rep = obj.cwd.replace('core/framework', ''), route = request.path.replace(obj.server.options.base_url, ''), filename = path.join(rep, route), filePrivate = obj.isProtectedFile(route);
129
+ let fs = require('fs'),
130
+ rep = obj.cwd.replace('core/framework', ''),
131
+ route = request.path.replace(obj.server.options.base_url, ''),
132
+ filename = path.join(rep, route),
133
+ filePrivate = obj.isProtectedFile(route);
130
134
 
131
135
  fs.exists(filename, function (exists) {
132
136
 
@@ -134,6 +138,12 @@ class Router {
134
138
 
135
139
  var acceptEncoding = (req.headers['accept-encoding'] != undefined) ? req.headers['accept-encoding'] : '';
136
140
  var fileStream = fs.createReadStream(filename);
141
+
142
+ if (ext === 'js' && !route.match(/vanilla\.min\.js$/)) {
143
+ extHeader['Cache-Control'] = 'public, max-age=15552000';
144
+ extHeader['Expires'] = new Date(Date.now() + 15552000000).toUTCString();
145
+ }
146
+
137
147
  if (acceptEncoding.match(/\bgzip\b/) && compressionMimes[ext] != undefined) {
138
148
  extHeader['Content-Encoding'] = 'gzip';
139
149
  res.writeHead(200, extHeader);
@@ -1,8 +1,3 @@
1
- /**
2
- Version 3.5
3
- Created by: nalancer08 <https://github.com/nalancer08>
4
- **/
5
-
6
1
  const _ = require('underscore');
7
2
  const http = require('http');
8
3
  const http2 = require('http2');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vanilla-jet",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "VannilaJet framework",
5
5
  "main": "index.js",
6
6
  "scripts": {