@blaasvaer/frmwrk 0.2.3 → 0.2.4
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/handle-request.js +25 -4
- package/index.js +19 -18
- package/package 2.json +30 -0
- package/package.json +1 -1
package/handle-request.js
CHANGED
|
@@ -23,6 +23,7 @@ async function handleRequest( req, res ) {
|
|
|
23
23
|
// console.log("handleRequest, req", req );
|
|
24
24
|
const request_url = new URL( req.url, `http://${req.headers.host}`);
|
|
25
25
|
// console.log("handleRequest, request_url", request_url);
|
|
26
|
+
// console.log("handleRequest, request_url.searchParams", request_url.searchParams);
|
|
26
27
|
/**
|
|
27
28
|
* Set default status and header
|
|
28
29
|
* @type {Number}
|
|
@@ -42,7 +43,24 @@ async function handleRequest( req, res ) {
|
|
|
42
43
|
return;
|
|
43
44
|
} else {
|
|
44
45
|
return;
|
|
45
|
-
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Service Worker from root
|
|
51
|
+
*/
|
|
52
|
+
if (request_url.pathname === '/service-worker.js') {
|
|
53
|
+
// TODO: Set theme dynamically
|
|
54
|
+
var favicon = path.join('', 'service-worker.js');
|
|
55
|
+
res.statusCode = 200;
|
|
56
|
+
res.setHeader('Content-Type', 'text/javascript');
|
|
57
|
+
|
|
58
|
+
if ( fs.existsSync( favicon ) ) {
|
|
59
|
+
fs.createReadStream( favicon ).pipe( res );
|
|
60
|
+
return;
|
|
61
|
+
} else {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
46
64
|
}
|
|
47
65
|
|
|
48
66
|
/**
|
|
@@ -65,7 +83,7 @@ async function handleRequest( req, res ) {
|
|
|
65
83
|
|
|
66
84
|
switch ( method ) {
|
|
67
85
|
case 'GET':
|
|
68
|
-
if ( ! controller.route.params ) {
|
|
86
|
+
if ( ! controller.route.params?.authorize ) {
|
|
69
87
|
/**
|
|
70
88
|
* If the route has no parameters, then just run the route method and serve whatever it may …
|
|
71
89
|
*/
|
|
@@ -75,14 +93,17 @@ async function handleRequest( req, res ) {
|
|
|
75
93
|
* Authorization
|
|
76
94
|
*/
|
|
77
95
|
if ( Authorize( controller.route ) ) {
|
|
96
|
+
// console.log(`We're authorized!`, controller.route.params);
|
|
78
97
|
response_output = await controller.view();
|
|
79
98
|
} else {
|
|
99
|
+
// console.log(`We're NOT authorized!`, controller.route.params);
|
|
80
100
|
/**
|
|
81
101
|
* Redirect the user to login if auth fails
|
|
82
102
|
*/
|
|
83
|
-
if ( controller.route.params.
|
|
103
|
+
if ( controller.route.params.authorize.redirect ) {
|
|
104
|
+
// console.log('controller.route.params.redirect', controller.route.params.redirect);
|
|
84
105
|
status_code = 302;
|
|
85
|
-
res.setHeader( 'Location', controller.route.params.
|
|
106
|
+
res.setHeader( 'Location', controller.route.params.authorize.redirect );
|
|
86
107
|
}
|
|
87
108
|
// console.log("NO USER", controller.route.params.redirect);
|
|
88
109
|
// response_output = redirect.action.call();
|
package/index.js
CHANGED
|
@@ -46,14 +46,6 @@ FW = function ( config ) {
|
|
|
46
46
|
controllers = {};
|
|
47
47
|
models = {};
|
|
48
48
|
|
|
49
|
-
/**
|
|
50
|
-
* Create and start the server
|
|
51
|
-
* @return {function} Server instance
|
|
52
|
-
*/
|
|
53
|
-
http.createServer( handleRequest ).listen(port, hostname, () => {
|
|
54
|
-
console.log(`Server running at http://${hostname}:${port}`);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
49
|
/**
|
|
58
50
|
* Set the Controller
|
|
59
51
|
* @param {string} name The name of the controller
|
|
@@ -75,7 +67,7 @@ FW = function ( config ) {
|
|
|
75
67
|
route.req = this.req;
|
|
76
68
|
route.res = this.res;
|
|
77
69
|
route.url = this.url;
|
|
78
|
-
|
|
70
|
+
|
|
79
71
|
/**
|
|
80
72
|
* Add search params to route
|
|
81
73
|
*/
|
|
@@ -95,12 +87,13 @@ FW = function ( config ) {
|
|
|
95
87
|
/**
|
|
96
88
|
* Check for authorization parameters.
|
|
97
89
|
*/
|
|
98
|
-
|
|
90
|
+
// if ( route.params !== null ) {
|
|
99
91
|
// console.log("Params not null", route.params);
|
|
100
|
-
|
|
101
|
-
console.log("This route should be authorized!");
|
|
102
|
-
|
|
103
|
-
|
|
92
|
+
// if ( route.params.authorize !== undefined ) {
|
|
93
|
+
// console.log("This route should be authorized!");
|
|
94
|
+
// Authorize( route.params );
|
|
95
|
+
// }
|
|
96
|
+
// }
|
|
104
97
|
|
|
105
98
|
return this;
|
|
106
99
|
}
|
|
@@ -109,8 +102,9 @@ console.log("This route should be authorized!");
|
|
|
109
102
|
* TODO: Authorize user
|
|
110
103
|
*/
|
|
111
104
|
Authorize = function Authorize ( credentials ) {
|
|
112
|
-
|
|
113
|
-
return
|
|
105
|
+
console.log("Authorize - check credentials:", credentials);
|
|
106
|
+
return false;
|
|
107
|
+
// return true;
|
|
114
108
|
}
|
|
115
109
|
|
|
116
110
|
/**
|
|
@@ -119,10 +113,17 @@ console.log("This route should be authorized!");
|
|
|
119
113
|
Install( config )
|
|
120
114
|
.then(( result ) => {
|
|
121
115
|
/**
|
|
122
|
-
* Run post install processes here …
|
|
116
|
+
* Run optional post install processes here …
|
|
123
117
|
*/
|
|
124
118
|
|
|
125
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Create and start the server
|
|
121
|
+
* @return {function} Server instance
|
|
122
|
+
*/
|
|
123
|
+
http.createServer( handleRequest ).listen(port, hostname, () => {
|
|
124
|
+
console.log(`Server running at http://${hostname}:${port}`);
|
|
125
|
+
});
|
|
126
|
+
})
|
|
126
127
|
.catch(function( err ) {
|
|
127
128
|
console.log("Install Error:", err);
|
|
128
129
|
});;
|
package/package 2.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@blaasvaer/frmwrk",
|
|
3
|
+
"version": "0.1.14",
|
|
4
|
+
"description": "My personal Node framework",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"patch": "npm version patch --force && npm publish",
|
|
9
|
+
"major": "npm version major --force && npm publish",
|
|
10
|
+
"minor": "npm version minor --force && npm publish"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+ssh://git@bitbucket.org/blaasvaer/frmwrk.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"Node",
|
|
18
|
+
"Framework",
|
|
19
|
+
"Homebrew"
|
|
20
|
+
],
|
|
21
|
+
"author": "Sam Blåsvær",
|
|
22
|
+
"license": "ISC",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://bitbucket.org/blaasvaer/frmwrk/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://bitbucket.org/blaasvaer/frmwrk#readme",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"serve-handler": "^6.1.3"
|
|
29
|
+
}
|
|
30
|
+
}
|