vanilla-jet 1.0.0 → 1.0.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.
@@ -6,111 +6,110 @@
6
6
  const _ = require('underscore');
7
7
  const http = require('http');
8
8
  const http2 = require('http2');
9
- const url = require('url') ;
10
9
  const fs = require('fs');
11
10
  const nunjucks = require('nunjucks');
12
11
  const path = require('path');
13
12
 
14
- var Router = require('./router.js');
15
- var Dipper = require('./dipper.js');
16
- var Functions = require('../external/functions.js');
13
+ let Router = require('./router.js');
14
+ let Dipper = require('./dipper.js');
17
15
 
18
- function Server(options) {
16
+ class Server {
19
17
 
20
- this.httpx = null;
21
- this.verbose = true;
22
- this.router = null;
23
- this.functions = null;
24
- this.dipper = null;
25
- this.init(options);
26
- }
18
+ constructor(options, functionsModule) {
19
+
20
+ console.log(functionsModule);
21
+
22
+ this.httpx = null;
23
+ this.verbose = true;
24
+ this.router = null;
25
+ this.functions = null;
26
+ this.dipper = null;
27
+ this.init(options, functionsModule);
28
+ }
27
29
 
28
- Server.prototype.init = function(options) {
29
-
30
- var obj = this,
31
- settings = options.settings,
32
- opts = settings[options.profile] || {},
33
- shared = settings['shared'] || {},
34
- security = settings['security'] || {};
35
-
36
- _.defaults(opts, {
37
- base_url: '',
38
- site_url: '',
39
- wsServer: false,
40
- onNotFound: obj.onNotFound
41
- });
42
- obj.options = opts;
43
-
44
- _.defaults(security, {
45
- pass_salt: '1234567890',
46
- token_salt: '0987654321',
47
- version: '1.0'
48
- });
49
- obj.security = security;
50
-
51
- // Render
52
- global.render = nunjucks.configure(path.join(process.cwd(), 'assets'), {
53
- autoescape: false,
54
- throwOnUndefined: true,
55
- noCache: true,
56
- });
57
- global.dipper = new Dipper(opts, shared);
58
-
59
- // Cheking for http or https
60
- if (/^((http):\/\/)/.test(obj.options.site_url) || /^((localhost))/.test(obj.options.site_url)) {
61
-
62
- obj.httpx = http.createServer((req, res) => {
63
- //console.log(req.url);
64
- obj.router.onRequest.call(obj.router, req, res);
30
+ init(options, functionsModule) {
31
+
32
+ let obj = this, settings = options.settings, opts = settings[options.profile] || {}, shared = settings['shared'] || {}, security = settings['security'] || {};
33
+
34
+ _.defaults(opts, {
35
+ base_url: '',
36
+ site_url: '',
37
+ wsServer: false,
38
+ onNotFound: obj.onNotFound
65
39
  });
40
+ obj.options = opts;
66
41
 
67
- } else if (/^((https):\/\/)/.test(obj.options.site_url)) {
42
+ _.defaults(security, {
43
+ pass_salt: '1234567890',
44
+ token_salt: '0987654321',
45
+ version: '1.0'
46
+ });
47
+ obj.security = security;
68
48
 
69
- certs = {
70
- key: fs.readFileSync(obj.security.key, 'utf8'),
71
- cert: fs.readFileSync(obj.security.cert, 'utf8'),
72
- allowHTTP1: true
73
- };
74
- obj.httpx = http2.createSecureServer(certs, (req, res) => {
75
- obj.router.onRequest.call(obj.router, req, res);
49
+ // Render
50
+ global.render = nunjucks.configure(path.join(process.cwd(), 'assets'), {
51
+ autoescape: false,
52
+ throwOnUndefined: true,
53
+ noCache: true,
76
54
  });
77
- }
55
+ global.dipper = new Dipper(opts, shared);
78
56
 
79
- obj.onNotFound = opts.onNotFound;
57
+ // Cheking for http or https
58
+ if (/^((http):\/\/)/.test(obj.options.site_url) || /^((localhost))/.test(obj.options.site_url)) {
80
59
 
81
- // Initialize router
82
- obj.router = new Router(obj);
60
+ obj.httpx = http.createServer((req, res) => {
61
+ //console.log(req.url);
62
+ obj.router.onRequest.call(obj.router, req, res);
63
+ });
83
64
 
84
- // Setting endpoints
85
- obj.functions = new Functions(obj);
86
- };
65
+ } else if (/^((https):\/\/)/.test(obj.options.site_url)) {
87
66
 
88
- Server.prototype.start = function() {
67
+ certs = {
68
+ key: fs.readFileSync(obj.security.key, 'utf8'),
69
+ cert: fs.readFileSync(obj.security.cert, 'utf8'),
70
+ allowHTTP1: true
71
+ };
72
+ obj.httpx = http2.createSecureServer(certs, (req, res) => {
73
+ obj.router.onRequest.call(obj.router, req, res);
74
+ });
75
+ }
89
76
 
90
- var obj = this;
91
- var port = (obj.options.port && obj.options.port != '') ? obj.options.port : 8080;
77
+ obj.onNotFound = opts.onNotFound;
92
78
 
93
- // Listen on the specified port
94
- obj.httpx.listen(port);
79
+ // Initialize router
80
+ obj.router = new Router(obj);
95
81
 
96
- // Logging
97
- obj.log('__________________ Dragonfly server started ___________________');
98
- obj.log(` > Listening on ${obj.options.site_url}:${obj.options.port}${obj.options.base_url} < `);
99
- obj.log('-----------------------------------------------------------------');
100
- };
82
+ // Setting endpoints
83
+ obj.functions = new functionsModule(obj);
84
+ }
85
+
86
+ start() {
101
87
 
102
- Server.prototype.log = function(value) {
88
+ let obj = this;
89
+ let port = (obj.options.port && obj.options.port != '') ? obj.options.port : 8080;
103
90
 
104
- var obj = this;
105
- if (obj.verbose) {
106
- console.log(value);
91
+ // Listen on the specified port
92
+ obj.httpx.listen(port);
93
+
94
+ // Logging
95
+ obj.log('__________________ Dragonfly server started ___________________');
96
+ obj.log(` > Listening on ${obj.options.site_url}:${obj.options.port}${obj.options.base_url} < `);
97
+ obj.log('-----------------------------------------------------------------');
107
98
  }
108
- };
109
99
 
110
- Server.prototype.onNotFound = function(request, response) {
100
+ log(value) {
111
101
 
112
- response.setStatus(404);
113
- response.respond();
114
- };
102
+ let obj = this;
103
+ if (obj.verbose) {
104
+ console.log(value);
105
+ }
106
+ }
107
+
108
+ onNotFound(request, response) {
109
+
110
+ response.setStatus(404);
111
+ response.respond();
112
+ }
113
+ }
115
114
 
116
115
  module.exports = Server;
package/index.js CHANGED
@@ -1,5 +1,13 @@
1
- function helloNpm() {
2
- return "hello NPM"
3
- }
4
-
5
- module.exports = helloNpm
1
+ const Dipper = require('./framework/dipper.js');
2
+ const Request = require('./framework/request.js');
3
+ const Response = require('./framework/response.js');
4
+ const Router = require('./framework/router.js');
5
+ const Server = require('./framework/server.js');
6
+
7
+ module.exports = {
8
+ Dipper,
9
+ Request,
10
+ Response,
11
+ Router,
12
+ Server
13
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vanilla-jet",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "VannilaJet framework",
5
5
  "main": "index.js",
6
6
  "scripts": {