@blaasvaer/frmwrk 0.2.6 → 0.3.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/index.js +32 -17
- package/package.json +1 -1
- package/package 2.json +0 -30
package/index.js
CHANGED
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
* Native modules
|
|
11
11
|
*/
|
|
12
12
|
const http = require('http');
|
|
13
|
+
const { Server } = require('socket.io');
|
|
14
|
+
|
|
15
|
+
let port;
|
|
16
|
+
let _config;
|
|
17
|
+
let _io;
|
|
18
|
+
|
|
13
19
|
/**
|
|
14
20
|
* Custom modules
|
|
15
21
|
*/
|
|
@@ -19,15 +25,18 @@ const Utils = require('./utils');
|
|
|
19
25
|
/**
|
|
20
26
|
* Define variables
|
|
21
27
|
*/
|
|
22
|
-
let hostname
|
|
23
|
-
server;
|
|
28
|
+
let hostname;
|
|
24
29
|
|
|
25
30
|
/**
|
|
26
31
|
* If port number is passed in as first (custom) parameter, set port
|
|
27
32
|
* otherwise use default 3000
|
|
28
33
|
* @type {Number}
|
|
29
34
|
*/
|
|
30
|
-
|
|
35
|
+
if ( ! process.env.NODE_PORT ) {
|
|
36
|
+
port = ( process.argv.length > 2 ) ? parseInt( process.argv[ process.argv.length - 1 ] ) : 3000;
|
|
37
|
+
} else {
|
|
38
|
+
port = process.env.NODE_PORT;
|
|
39
|
+
}
|
|
31
40
|
|
|
32
41
|
if ( process.env.NODE_ENV !== 'production') {
|
|
33
42
|
// console.log("ENV file", process.env.PGHOST);
|
|
@@ -39,12 +48,9 @@ if ( process.env.NODE_ENV !== 'production') {
|
|
|
39
48
|
* @return {Node} Node
|
|
40
49
|
*/
|
|
41
50
|
FW = function ( config ) {
|
|
42
|
-
|
|
51
|
+
_config = config || {};
|
|
43
52
|
|
|
44
|
-
hostname =
|
|
45
|
-
|
|
46
|
-
controllers = {};
|
|
47
|
-
models = {};
|
|
53
|
+
hostname = _config.hostname ? _config.hostname : '0.0.0.0';
|
|
48
54
|
|
|
49
55
|
/**
|
|
50
56
|
* Set the Controller
|
|
@@ -107,6 +113,10 @@ console.log("Authorize - check credentials:", credentials);
|
|
|
107
113
|
// return true;
|
|
108
114
|
}
|
|
109
115
|
|
|
116
|
+
getSocketIO = () => {
|
|
117
|
+
return _io;
|
|
118
|
+
}
|
|
119
|
+
|
|
110
120
|
/**
|
|
111
121
|
* Install framework components and start the server
|
|
112
122
|
*/
|
|
@@ -120,13 +130,19 @@ console.log("Authorize - check credentials:", credentials);
|
|
|
120
130
|
* Create and start the server
|
|
121
131
|
* @return {function} Server instance
|
|
122
132
|
*/
|
|
123
|
-
http.createServer( handleRequest ).listen(port, hostname, () => {
|
|
133
|
+
const server = http.createServer( handleRequest ).listen(port, hostname, () => {
|
|
124
134
|
console.log(`Server running at http://${hostname}:${port}`);
|
|
125
135
|
});
|
|
136
|
+
|
|
137
|
+
if ( config.enable_socket_io ) {
|
|
138
|
+
_io = new Server( server );
|
|
139
|
+
}
|
|
126
140
|
})
|
|
127
141
|
.catch(function( err ) {
|
|
128
142
|
console.log("Install Error:", err);
|
|
129
|
-
})
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return this;
|
|
130
146
|
};
|
|
131
147
|
|
|
132
148
|
/**
|
|
@@ -135,19 +151,18 @@ console.log("Install Error:", err);
|
|
|
135
151
|
* Installs the components of the framework like; controllers, models, views, users etc.
|
|
136
152
|
* @param {Object} config Config object
|
|
137
153
|
*/
|
|
138
|
-
global.Install =
|
|
139
|
-
|
|
140
|
-
global.publicPath = config.root + '/themes/' + config.theme;
|
|
154
|
+
global.Install = () => {
|
|
155
|
+
global.publicPath = _config.root + '/themes/' + _config.theme;
|
|
141
156
|
|
|
142
157
|
/**
|
|
143
158
|
* Installation processes to run
|
|
144
159
|
* @type {Array}
|
|
145
160
|
*/
|
|
146
161
|
let install_processes = [
|
|
147
|
-
require('./controllers')(
|
|
148
|
-
require('./models')(
|
|
149
|
-
require('./views')(
|
|
150
|
-
require('./connections')(
|
|
162
|
+
require('./controllers')( _config ),
|
|
163
|
+
require('./models')( _config ),
|
|
164
|
+
require('./views')( _config ),
|
|
165
|
+
require('./connections')( _config ),
|
|
151
166
|
// require('./users')( config )
|
|
152
167
|
];
|
|
153
168
|
|
package/package.json
CHANGED
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
|
-
}
|