@blaasvaer/frmwrk 0.2.0 → 0.2.1

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/connections.js CHANGED
@@ -4,7 +4,7 @@ const utils = require('./utils');
4
4
  * Install connections
5
5
  */
6
6
  function installconnections ( config ) {
7
- FW.connections = FW.connections || {};
7
+ FW.databases = {};
8
8
 
9
9
  let connections_dir = config.root + '/connections/';
10
10
 
@@ -14,6 +14,8 @@ function installconnections ( config ) {
14
14
  const connection_files = [];
15
15
 
16
16
  files.forEach( file => {
17
+ let connection_name = file.split('.')[0];
18
+
17
19
  // Skip file if name start with an underscore
18
20
  if ( file.charAt(0) === '_' )
19
21
  return;
@@ -23,20 +25,13 @@ function installconnections ( config ) {
23
25
  let connection = require( connections_dir + file );
24
26
 
25
27
  if ( connection ) {
26
- // FW.connections[ path.parse(file).name ] = connection;
27
- FW.connections[ file.split('.')[0] ] = connection;
28
-
29
- // Check for config connection type
30
- if ( config.connection && FW.connections[ config.connection ] ) {
31
- FW.database = FW.connections[ config.connection ];
32
- }
33
-
28
+ FW.databases[ connection_name ] = connection;
29
+
34
30
  resolve( file );
35
31
  } else {
36
32
  reject( "Loading of connection: " + file + " failed!" );
37
33
  }
38
- });
39
-
34
+ });
40
35
  connection_files.push( promise );
41
36
  });
42
37
 
package/handle-request.js CHANGED
@@ -49,8 +49,7 @@ async function handleRequest( req, res ) {
49
49
  * Find route in Router based on url
50
50
  */
51
51
  const route = findRoute( request_url );
52
- // console.log("request_url", request_url);
53
- // console.log("route", route);
52
+
54
53
  /**
55
54
  * Check for complete route
56
55
  * @param {[type]} route [description]
@@ -62,26 +61,39 @@ async function handleRequest( req, res ) {
62
61
  */
63
62
  const controller = new Controller( route, req, res, request_url );
64
63
 
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 …`;
64
+ let response_output = 'Nothing here …';
81
65
 
82
66
  switch ( method ) {
83
67
  case 'GET':
84
- response_output = await controller.view();
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
+ }
85
97
 
86
98
  res.statusCode = status_code;
87
99
  res.setHeader( 'Content-Type', content_types[content_type] );
package/index.js CHANGED
@@ -92,6 +92,16 @@ 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
+
95
105
  return this;
96
106
  }
97
107
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaasvaer/frmwrk",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "My personal Node framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/package 2.json DELETED
@@ -1,30 +0,0 @@
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
- }