@blaasvaer/frmwrk 0.1.16 → 0.1.19

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.
@@ -14,10 +14,7 @@
14
14
  "titleBar.activeForeground": "#e7e7e7",
15
15
  "titleBar.inactiveBackground": "#21573299",
16
16
  "titleBar.inactiveForeground": "#e7e7e799",
17
- "editorGroup.border": "#2f7c47",
18
- "panel.border": "#2f7c47",
19
17
  "sash.hoverBorder": "#2f7c47",
20
- "sideBar.border": "#2f7c47",
21
18
  "statusBarItem.remoteBackground": "#215732",
22
19
  "statusBarItem.remoteForeground": "#e7e7e7"
23
20
  },
package/handle-request.js CHANGED
@@ -49,6 +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
+
52
53
  /**
53
54
  * Check for complete route
54
55
  * @param {[type]} route [description]
@@ -58,10 +59,10 @@ async function handleRequest( req, res ) {
58
59
  /**
59
60
  * Create new controller from route
60
61
  */
61
- const controller = new Controller( route, req, res );
62
+ const controller = new Controller( route, req, res, request_url );
62
63
 
63
64
  let response_output = 'Nothing here …';
64
-
65
+
65
66
  switch ( method ) {
66
67
  case 'GET':
67
68
  if ( ! controller.route.params ) {
@@ -96,6 +97,8 @@ async function handleRequest( req, res ) {
96
97
 
97
98
  res.statusCode = status_code;
98
99
  res.setHeader( 'Content-Type', content_types[content_type] );
100
+ res.setHeader( 'Access-Control-Allow-Origin', 'http://localhost');
101
+ res.setHeader( 'Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
99
102
  // res.setHeader( 'Content-Security-Policy', "default-src 'self'; font-src 'self'; img-src 'self'; script-src 'self'; style-src 'self'; frame-src 'self'");
100
103
  // res.setHeader( 'Content-Security-Policy', "default-src 'self'; img-src 'self';");
101
104
 
package/index.js CHANGED
@@ -60,12 +60,11 @@ FW = function ( config ) {
60
60
  * @param {object} req The incomming request object
61
61
  * @param {object} res The response object
62
62
  */
63
- Controller = function Controller ( route, req, res ) {
64
- // console.log("Controller in index (req.method):\n", req.method);
65
- // console.log("Controller in index (req):\n", req);
63
+ Controller = function Controller ( route, req, res, url ) {
66
64
  this.route = route;
67
65
  this.req = req;
68
66
  this.res = res;
67
+ this.url = url;
69
68
  this.route.method = req.method;
70
69
 
71
70
  /**
@@ -75,6 +74,19 @@ FW = function ( config ) {
75
74
  route.data = data;
76
75
  route.req = this.req;
77
76
  route.res = this.res;
77
+ route.url = this.url;
78
+
79
+ /**
80
+ * Add search params to route
81
+ */
82
+ let params = {};
83
+
84
+ for ( let pair of url.searchParams) {
85
+ params[pair[0]] = pair[1];
86
+ }
87
+
88
+ route.searchParams = params;
89
+
78
90
  let output = await route.action( route );
79
91
 
80
92
  return output;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaasvaer/frmwrk",
3
- "version": "0.1.16",
3
+ "version": "0.1.19",
4
4
  "description": "My personal Node framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/router.js CHANGED
@@ -30,55 +30,47 @@ global.ROUTE = function ( route, action, params = null ) {
30
30
  global.routes.push( r );
31
31
  };
32
32
 
33
- function Router ( req, url ) {
34
- const method = req.method;
35
- // console.log("Router url:", url);
36
- // Split url into array
37
- let url_array = url.pathname.split('/');
33
+ // function Router ( req, url ) {
34
+ // const method = req.method;
35
+ // // console.log("Router url:", url);
36
+ // // Split url into array
37
+ // let url_array = url.pathname.split('/');
38
38
 
39
- // Remove first empty element
40
- url_array.shift();
39
+ // // Remove first empty element
40
+ // url_array.shift();
41
41
 
42
- // Set controller, resource, resource_id, search, searchParams
43
- this.controller = url_array[0];
44
- this.resource = url_array[1];
45
- this.resource_id = url_array[2];
46
- this.search = url_array[3];
47
- this.searchParams = url_array[4];
42
+ // // Set controller, resource, resource_id, search, searchParams
43
+ // this.controller = url_array[0];
44
+ // this.resource = url_array[1];
45
+ // this.resource_id = url_array[2];
46
+ // this.search = url_array[3];
47
+ // this.searchParams = url_array[4];
48
48
 
49
- // console.log("referer", referer);
50
- // console.log("url", url);
51
- // console.log("this.controller", this.controller);
52
- // console.log("this.resource", this.resource);
53
- // console.log("this.resource_id", this.resource_id);
54
- // console.log("this.search", this.search);
55
- // console.log("this.searchParams", this.searchParams);
49
+ // // console.log("referer", referer);
50
+ // // console.log("url", url);
51
+ // // console.log("this.controller", this.controller);
52
+ // // console.log("this.resource", this.resource);
53
+ // // console.log("this.resource_id", this.resource_id);
54
+ // // console.log("this.search", this.search);
55
+ // // console.log("this.searchParams", this.searchParams);
56
56
 
57
- return this;
58
- };
57
+ // return this;
58
+ // };
59
59
 
60
60
  function findRoute ( url ) {
61
61
  let pathname = url.pathname;
62
- // console.log( "ROUTE, url", url );
63
62
 
64
- // console.log("THIS", this);
65
- // Check if route exist
66
63
  let route = global.routes.find( ( obj ) => obj.route === FW.utils.removeTrailingSlashes( pathname ) );
67
64
 
68
65
  if ( route ) {
69
- // console.log("Route defined url:", url);
70
- // console.log("Route defined route:", route);
71
- // Execute action for route
72
66
  return route;
73
67
  } else {
74
- // console.log("Route NOT defined", url);
75
68
  const url_array = pathname.split('/').filter( e => e );
76
69
 
77
70
  // Check if route is an API call
78
71
  let isAPICall = pathname.split('/')[1] === 'api' ? true : false;
79
72
 
80
73
  if ( isAPICall ) {
81
- // console.log("Route NOT defined (API)", url, url.split('/')[1]);
82
74
  /**
83
75
  * If checking for UUID use:
84
76
  * UUID v1:
@@ -122,6 +114,6 @@ function findRoute ( url ) {
122
114
  }
123
115
 
124
116
  module.exports = {
125
- Router,
117
+ // Router,
126
118
  findRoute
127
119
  }