alchemymvc 1.1.6 → 1.1.10

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.
@@ -1,5 +1,3 @@
1
- var slug = alchemy.use('mollusc');
2
-
3
1
  /**
4
2
  * The Sluggable Behaviour class
5
3
  *
@@ -293,7 +291,7 @@ Sluggable.setMethod(function createSlug(record, new_value, callback) {
293
291
  *
294
292
  * @author Jelle De Loecker <jelle@develry.be>
295
293
  * @since 0.1.0
296
- * @version 1.1.0
294
+ * @version 1.1.8
297
295
  *
298
296
  * @param {String} title
299
297
  * @param {String} path
@@ -336,7 +334,7 @@ Sluggable.setMethod(function generateSlug(title, key, record, callback) {
336
334
  return callback();
337
335
  }
338
336
 
339
- baseSlug = slug(title, {replacement: that.replacement || '-'}).toLowerCase();
337
+ baseSlug = title.slug(that.replacement || '-').toLowerCase();
340
338
  current = baseSlug;
341
339
  model = Model.get(this.model.name);
342
340
  count = 1;
@@ -1,193 +1,174 @@
1
- /**
2
- * The Http Conduit Class
3
- *
4
- * @author Jelle De Loecker <jelle@develry.be>
5
- * @since 0.2.0
6
- * @version 1.1.3
7
- *
8
- * @param {IncomingMessage} req
9
- * @param {ServerResponse} res
10
- * @param {Router} router
11
- */
12
- var HttpConduit = Function.inherits('Alchemy.Conduit.Conduit', function Http(req, res, router) {
13
-
14
- // Initialize basic conduit values
15
- Http.super.call(this);
16
-
17
- this.initHttp(req, res, router);
18
- });
19
-
20
- /**
21
- * Has the client aborted the request?
22
- *
23
- * @author Jelle De Loecker <jelle@develry.be>
24
- * @since 1.1.0
25
- * @version 1.1.0
26
- *
27
- * @type {Boolean}
28
- */
29
- HttpConduit.setProperty(function aborted() {
30
-
31
- if (this.request && this.request.aborted != null) {
32
- return this.request.aborted;
33
- }
34
-
35
- return false;
36
- });
37
-
38
- /**
39
- * Return the IP address
40
- *
41
- * @author Jelle De Loecker <jelle@develry.be>
42
- * @since 0.2.0
43
- * @version 1.1.0
44
- */
45
- HttpConduit.setProperty(function ip() {
46
-
47
- var req = this.request;
48
-
49
- if (!req) {
50
- return null;
51
- }
52
-
53
- let forwarded_for = req.headers['x-forwarded-for'] || req.headers['x-real-ip'];
54
-
55
- if (forwarded_for) {
56
-
57
- // Forwarded for can contain multiple ip addresses,
58
- // return the first one
59
- if (forwarded_for.indexOf(',') > -1) {
60
- forwarded_for = forwarded_for.before(',');
61
- }
62
-
63
- return forwarded_for;
64
- }
65
-
66
- let remote_address;
67
-
68
- if (req.connection) {
69
- remote_address = req.connection.remoteAddress;
70
- }
71
-
72
- if (!remote_address && req.socket) {
73
- remote_address = req.socket.remoteAddress;
74
- }
75
-
76
- if (!remote_address && req.connection && req.connection.socket) {
77
- remote_address = req.connection.socket.remoteAddress;
78
- }
79
-
80
- return remote_address;
81
- });
82
-
83
- /**
84
- * Get a simple fingerprint of the client
85
- * based on ip, accept-language & user-agent
86
- *
87
- * @author Jelle De Loecker <jelle@develry.be>
88
- * @since 1.1.0
89
- * @version 1.1.0
90
- *
91
- * @type {String}
92
- */
93
- HttpConduit.enforceProperty(function fingerprint() {
94
-
95
- let result,
96
- language = this.headers['accept-language'] || 'all',
97
- ua = this.headers['user-agent'] || 'unknown',
98
- ip = this.ip || '';
99
-
100
- result = Object.checksum(ip + '_' + language + '_' + ua);
101
-
102
- return result;
103
- });
104
-
105
- /**
106
- * Init
107
- *
108
- * @author Jelle De Loecker <jelle@kipdola.be>
109
- * @since 0.3.3
110
- * @version 1.1.0
111
- *
112
- * @param {IncomingMessage} req
113
- * @param {ServerResponse} res
114
- * @param {Router} router
115
- */
116
- HttpConduit.setMethod(async function initHttp(req, res, router) {
117
-
118
- if (req != null) {
119
- // Make conduit available in req
120
- req.conduit = this;
121
-
122
- // Basic HTTP objects
123
- this.request = req;
124
-
125
- // The HTTP request headers
126
- this.headers = req.headers;
127
-
128
- // Parse the original URL without host
129
- this.original_url = new RURL(req.url);
130
-
131
- // Is this an AJAX request?
132
- this.ajax = null;
133
- }
134
-
135
- if (res != null) {
136
- this.response = res;
137
- }
138
-
139
- if (router) {
140
- this.router = router;
141
- }
142
-
143
- // The HTTP status
144
- this.status = 200;
145
-
146
- this.debugMark('Parse request');
147
-
148
- // Parse the request, get the correct routes and such
149
- await this.parseRequest();
150
-
151
- if (this.halt_request) {
152
- return;
153
- }
154
-
155
- if (alchemy.settings.debug || alchemy.settings.environment != 'live') {
156
- this.setHeader('X-Robots-Tag', 'none');
157
- }
158
-
159
- this.debugMark(false);
160
-
161
- // Call the middleware, which will call the handler afterwards
162
- this.callMiddleware();
163
- });
164
-
165
- /**
166
- * Get the original url path
167
- *
168
- * @author Jelle De Loecker <jelle@kipdola.be>
169
- * @since 1.1.0
170
- * @version 1.1.0
171
- *
172
- * @type {String}
173
- */
174
- HttpConduit.setProperty(function original_path() {
175
- return this.original_url.path;
176
- }, function setPath(value) {
177
- return this.original_url.path = value;
178
- });
179
-
180
- /**
181
- * Get the original url pathname
182
- *
183
- * @author Jelle De Loecker <jelle@kipdola.be>
184
- * @since 1.1.0
185
- * @version 1.1.0
186
- *
187
- * @type {String}
188
- */
189
- HttpConduit.setProperty(function original_pathname() {
190
- return this.original_url.pathname;
191
- }, function setPathname(value) {
192
- return this.original_url.pathname = value;
1
+ /**
2
+ * The Http Conduit Class
3
+ *
4
+ * @author Jelle De Loecker <jelle@develry.be>
5
+ * @since 0.2.0
6
+ * @version 1.1.3
7
+ *
8
+ * @param {IncomingMessage} req
9
+ * @param {ServerResponse} res
10
+ * @param {Router} router
11
+ */
12
+ var HttpConduit = Function.inherits('Alchemy.Conduit.Conduit', function Http(req, res, router) {
13
+
14
+ // Initialize basic conduit values
15
+ Http.super.call(this);
16
+
17
+ this.initHttp(req, res, router);
18
+ });
19
+
20
+ /**
21
+ * Has the client aborted the request?
22
+ *
23
+ * @author Jelle De Loecker <jelle@develry.be>
24
+ * @since 1.1.0
25
+ * @version 1.1.0
26
+ *
27
+ * @type {Boolean}
28
+ */
29
+ HttpConduit.setProperty(function aborted() {
30
+
31
+ if (this.request && this.request.aborted != null) {
32
+ return this.request.aborted;
33
+ }
34
+
35
+ return false;
36
+ });
37
+
38
+ /**
39
+ * Return the IP address
40
+ *
41
+ * @author Jelle De Loecker <jelle@develry.be>
42
+ * @since 0.2.0
43
+ * @version 1.1.0
44
+ */
45
+ HttpConduit.setProperty(function ip() {
46
+
47
+ var req = this.request;
48
+
49
+ if (!req) {
50
+ return null;
51
+ }
52
+
53
+ let forwarded_for = req.headers['x-forwarded-for'] || req.headers['x-real-ip'];
54
+
55
+ if (forwarded_for) {
56
+
57
+ // Forwarded for can contain multiple ip addresses,
58
+ // return the first one
59
+ if (forwarded_for.indexOf(',') > -1) {
60
+ forwarded_for = forwarded_for.before(',');
61
+ }
62
+
63
+ return forwarded_for;
64
+ }
65
+
66
+ let remote_address;
67
+
68
+ if (req.connection) {
69
+ remote_address = req.connection.remoteAddress;
70
+ }
71
+
72
+ if (!remote_address && req.socket) {
73
+ remote_address = req.socket.remoteAddress;
74
+ }
75
+
76
+ if (!remote_address && req.connection && req.connection.socket) {
77
+ remote_address = req.connection.socket.remoteAddress;
78
+ }
79
+
80
+ return remote_address;
81
+ });
82
+
83
+ /**
84
+ * Get a simple fingerprint of the client
85
+ * based on ip, accept-language & user-agent
86
+ *
87
+ * @author Jelle De Loecker <jelle@develry.be>
88
+ * @since 1.1.0
89
+ * @version 1.1.0
90
+ *
91
+ * @type {String}
92
+ */
93
+ HttpConduit.enforceProperty(function fingerprint() {
94
+
95
+ let result,
96
+ language = this.headers['accept-language'] || 'all',
97
+ ua = this.headers['user-agent'] || 'unknown',
98
+ ip = this.ip || '';
99
+
100
+ result = Object.checksum(ip + '_' + language + '_' + ua);
101
+
102
+ return result;
103
+ });
104
+
105
+ /**
106
+ * Init
107
+ *
108
+ * @author Jelle De Loecker <jelle@kipdola.be>
109
+ * @since 0.3.3
110
+ * @version 1.2.0
111
+ *
112
+ * @param {IncomingMessage} req
113
+ * @param {ServerResponse} res
114
+ * @param {Router} router
115
+ */
116
+ HttpConduit.setMethod(async function initHttp(req, res, router) {
117
+
118
+ this.setReqRes(req, res);
119
+
120
+ if (router) {
121
+ this.router = router;
122
+ }
123
+
124
+ // The HTTP status
125
+ this.status = 200;
126
+
127
+ this.debugMark('Parse request');
128
+
129
+ // Parse the request, get the correct routes and such
130
+ await this.parseRequest();
131
+
132
+ if (this.halt_request) {
133
+ return;
134
+ }
135
+
136
+ if (alchemy.settings.debug || alchemy.settings.environment != 'live') {
137
+ this.setHeader('X-Robots-Tag', 'none');
138
+ }
139
+
140
+ this.debugMark(false);
141
+
142
+ // Call the middleware, which will call the handler afterwards
143
+ this.callMiddleware();
144
+ });
145
+
146
+ /**
147
+ * Get the original url path
148
+ *
149
+ * @author Jelle De Loecker <jelle@kipdola.be>
150
+ * @since 1.1.0
151
+ * @version 1.1.0
152
+ *
153
+ * @type {String}
154
+ */
155
+ HttpConduit.setProperty(function original_path() {
156
+ return this.original_url.path;
157
+ }, function setPath(value) {
158
+ return this.original_url.path = value;
159
+ });
160
+
161
+ /**
162
+ * Get the original url pathname
163
+ *
164
+ * @author Jelle De Loecker <jelle@kipdola.be>
165
+ * @since 1.1.0
166
+ * @version 1.1.0
167
+ *
168
+ * @type {String}
169
+ */
170
+ HttpConduit.setProperty(function original_pathname() {
171
+ return this.original_url.pathname;
172
+ }, function setPathname(value) {
173
+ return this.original_url.pathname = value;
193
174
  });
@@ -76,9 +76,9 @@ LoopConduit.setMethod(function copyParentProperties(conduit) {
76
76
  /**
77
77
  * Set the loopback options
78
78
  *
79
- * @author Jelle De Loecker <jelle@develry.be>
79
+ * @author Jelle De Loecker <jelle@elevenways.be>
80
80
  * @since 1.1.3
81
- * @version 1.1.5
81
+ * @version 1.1.7
82
82
  *
83
83
  * @param {Object} options
84
84
  * @param {Function} callback
@@ -93,6 +93,9 @@ LoopConduit.setMethod(function setOptions(options, callback) {
93
93
  info,
94
94
  key;
95
95
 
96
+ // Always clone the options
97
+ options = JSON.clone(options);
98
+
96
99
  for (key in options) {
97
100
  let set_method = false;
98
101
 
@@ -113,13 +116,23 @@ LoopConduit.setMethod(function setOptions(options, callback) {
113
116
  }
114
117
  }
115
118
 
116
- if (!this.method) {
117
- this.method = 'get';
119
+ if (options.method) {
120
+ this.method = options.method;
118
121
  }
119
122
 
120
123
  if (options.name) {
121
124
  // @TODO: what about path sections?
122
- //route = this.getRouteByName(options.name);
125
+ route = this.getRouteByName(options.name);
126
+
127
+ if (route && !this.method) {
128
+ if (route.methods.length == 1) {
129
+ this.method = route.methods[0];
130
+ } else if (options.body && route.methods.indexOf('post') > -1) {
131
+ this.method = 'post';
132
+ } else {
133
+ this.method = route.methods[0];
134
+ }
135
+ }
123
136
 
124
137
  // @WARNING: It's best to just generate the URL
125
138
  // and let it parse all the information that way
@@ -127,6 +140,10 @@ LoopConduit.setMethod(function setOptions(options, callback) {
127
140
  // @TODO: alchemy.routeUrl will ignore the `keep_get_parameters` option
128
141
  }
129
142
 
143
+ if (!this.method) {
144
+ this.method = 'get';
145
+ }
146
+
130
147
  if (options.href) {
131
148
 
132
149
  this.original_url = RURL.parse(options.href);