@blaasvaer/frmwrk 0.1.19 → 0.2.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.
package/handle-request.js CHANGED
@@ -49,7 +49,8 @@ async function handleRequest( req, res ) {
49
49
  * Find route in Router based on url
50
50
  */
51
51
  const route = findRoute( request_url );
52
-
52
+ // console.log("request_url", request_url);
53
+ // console.log("route", route);
53
54
  /**
54
55
  * Check for complete route
55
56
  * @param {[type]} route [description]
@@ -61,39 +62,26 @@ async function handleRequest( req, res ) {
61
62
  */
62
63
  const controller = new Controller( route, req, res, request_url );
63
64
 
64
- let response_output = 'Nothing here …';
65
+ /**
66
+ * AUTHORIZATION
67
+ * Check for authorization parameters.
68
+ */
69
+ if ( route?.params !== null ) {
70
+ // console.log("Params not null", route.params);
71
+ let _redirect = (route.params?.redirect) ? route.params.redirect : '/login';
72
+
73
+ if ( route?.params?.authorize === true ) {
74
+ console.log("This route should be authorized!");
75
+ res.writeHead(301, { "Location": "http://" + req.headers['host'] + _redirect });
76
+ return res.end();
77
+ }
78
+ }
79
+
80
+ let response_output = `Nothing here …`;
65
81
 
66
82
  switch ( method ) {
67
83
  case 'GET':
68
- if ( ! controller.route.params ) {
69
- /**
70
- * If the route has no parameters, then just run the route method and serve whatever it may …
71
- */
72
- response_output = await controller.view();
73
- } else {
74
- /**
75
- * Authorization
76
- */
77
- if ( Authorize( controller.route ) ) {
78
- response_output = await controller.view();
79
- } else {
80
- /**
81
- * Redirect the user to login if auth fails
82
- */
83
- if ( controller.route.params.access.redirect ) {
84
- status_code = 302;
85
- res.setHeader( 'Location', controller.route.params.access.redirect );
86
- }
87
- // console.log("NO USER", controller.route.params.redirect);
88
- // response_output = redirect.action.call();
89
- // route.params.redirect.call();
90
- // response_output = 'Access denied';
91
- }
92
-
93
- if ( controller.route.params.type ) {
94
- content_type = controller.route.params.type;
95
- }
96
- }
84
+ response_output = await controller.view();
97
85
 
98
86
  res.statusCode = status_code;
99
87
  res.setHeader( 'Content-Type', content_types[content_type] );
package/index.js CHANGED
@@ -92,16 +92,6 @@ FW = function ( config ) {
92
92
  return output;
93
93
  }
94
94
 
95
- /**
96
- * Check for authorization parameters.
97
- */
98
- if ( route.params !== null ) {
99
- // console.log("Params not null", route.params);
100
- if ( route.params.access !== undefined ) {
101
- console.log("This route should be authorized!");
102
- }
103
- }
104
-
105
95
  return this;
106
96
  }
107
97
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaasvaer/frmwrk",
3
- "version": "0.1.19",
3
+ "version": "0.2.0",
4
4
  "description": "My personal Node framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,22 +0,0 @@
1
- {
2
- "workbench.colorCustomizations": {
3
- "activityBar.activeBackground": "#2f7c47",
4
- "activityBar.activeBorder": "#422c74",
5
- "activityBar.background": "#2f7c47",
6
- "activityBar.foreground": "#e7e7e7",
7
- "activityBar.inactiveForeground": "#e7e7e799",
8
- "activityBarBadge.background": "#422c74",
9
- "activityBarBadge.foreground": "#e7e7e7",
10
- "statusBar.background": "#215732",
11
- "statusBar.foreground": "#e7e7e7",
12
- "statusBarItem.hoverBackground": "#2f7c47",
13
- "titleBar.activeBackground": "#215732",
14
- "titleBar.activeForeground": "#e7e7e7",
15
- "titleBar.inactiveBackground": "#21573299",
16
- "titleBar.inactiveForeground": "#e7e7e799",
17
- "sash.hoverBorder": "#2f7c47",
18
- "statusBarItem.remoteBackground": "#215732",
19
- "statusBarItem.remoteForeground": "#e7e7e7"
20
- },
21
- "peacock.color": "#215732"
22
- }