@lmjs/cli 1.0.1 → 1.0.3
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 +3 -3
- package/lib/app.js +236 -92
- package/package.json +4 -8
package/index.js
CHANGED
|
@@ -103,7 +103,7 @@ async function buildProject(cmds) {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
beaCode += `
|
|
106
|
-
|
|
106
|
+
var _beaTn = "` + token_ + `";
|
|
107
107
|
`;
|
|
108
108
|
// let kkk = await axios.get(BEA_Libs.BEAJS + "/prod");
|
|
109
109
|
// beaCode += kkk.data;
|
|
@@ -126,12 +126,12 @@ let _beaTn = "` + token_ + `";
|
|
|
126
126
|
|
|
127
127
|
let zode = UglifyJS.minify(beaCode, {
|
|
128
128
|
mangle: {
|
|
129
|
-
reserved: ['_vcdata']
|
|
129
|
+
reserved: ['_vcdata','_ws']
|
|
130
130
|
}
|
|
131
131
|
});
|
|
132
132
|
let zode2 = UglifyJS.minify(js2, {
|
|
133
133
|
mangle: {
|
|
134
|
-
reserved: ['_vcdata']
|
|
134
|
+
reserved: ['_vcdata','_ws']
|
|
135
135
|
},
|
|
136
136
|
output: {
|
|
137
137
|
beautify: true
|
package/lib/app.js
CHANGED
|
@@ -1,116 +1,260 @@
|
|
|
1
1
|
var fs = require('fs');
|
|
2
2
|
const axios = require('axios').default;
|
|
3
3
|
const path = require("path");
|
|
4
|
-
|
|
5
|
-
var compression = require('compression');
|
|
6
|
-
const app = express();
|
|
7
|
-
const server = require('http').createServer(app);
|
|
8
|
-
const io = require('socket.io')(server, {
|
|
9
|
-
// wsEngine: require("eiows").Server,
|
|
10
|
-
// perMessageDeflate: {
|
|
11
|
-
// threshold: 32768
|
|
12
|
-
// },
|
|
13
|
-
maxHttpBufferSize: 400e6
|
|
14
|
-
});
|
|
15
|
-
var cookieParser = require('cookie-parser');
|
|
16
|
-
var expressSession = require('express-session');
|
|
17
|
-
const bodyParser = require('body-parser');
|
|
18
|
-
var multer = require('multer');
|
|
19
|
-
var upload = multer();
|
|
4
|
+
var uws = require('uWebSockets.js');
|
|
20
5
|
const fcs = require("./fcs.js");
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
resave: true,
|
|
25
|
-
saveUninitialized: true,
|
|
26
|
-
cookie: { maxAge: 9999000 }
|
|
27
|
-
});
|
|
28
|
-
|
|
6
|
+
const mime = require('mime-types');
|
|
7
|
+
var cl = console.log;
|
|
8
|
+
var zlib = require('zlib');
|
|
29
9
|
var config = fcs.getConfig();
|
|
30
10
|
var _views = {};
|
|
31
11
|
var _comps = {};
|
|
12
|
+
function toArrayBuffer(buffer) {
|
|
13
|
+
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
14
|
+
}
|
|
15
|
+
uws.App().ws('/*', {
|
|
32
16
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
app.use(bodyParser.urlencoded({ extended: true }));
|
|
39
|
-
app.use(bodyParser.json());
|
|
40
|
-
app.use(bodyParser.raw());
|
|
41
|
-
app.use(upload.array());
|
|
42
|
-
|
|
43
|
-
io.use(function (socket, next) {
|
|
44
|
-
session(socket.request, socket.request.res, next);
|
|
45
|
-
});
|
|
17
|
+
/* There are many common helper features */
|
|
18
|
+
idleTimeout: 8,
|
|
19
|
+
maxBackpressure: 1024 * 1024,
|
|
20
|
+
maxPayloadLength: 16 * 1024 * 1024,
|
|
21
|
+
compression: uws.SHARED_COMPRESSOR,
|
|
46
22
|
|
|
47
|
-
|
|
48
|
-
|
|
23
|
+
/* Handlers */
|
|
24
|
+
open: (ws) => {
|
|
25
|
+
// console.log('A WebSocket connected!');
|
|
26
|
+
ws.subscribe('/home/rat');
|
|
27
|
+
},
|
|
28
|
+
message: async (ws, message, isBinary) => {
|
|
29
|
+
/* Ok is false if backpressure was built up, wait for drain */
|
|
49
30
|
try {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
31
|
+
const buffer = Buffer.from(message);
|
|
32
|
+
const data = JSON.parse(buffer.toString());
|
|
33
|
+
|
|
34
|
+
if (data.hasOwnProperty('e')) {
|
|
35
|
+
var _data = {
|
|
36
|
+
"e": data.e,
|
|
37
|
+
"_iter": data._iter,
|
|
38
|
+
"payload": {}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
if (data.e == "getfiles") {
|
|
42
|
+
_data['payload'] = {
|
|
43
|
+
"views": _views,
|
|
44
|
+
"comps": _comps
|
|
45
|
+
};
|
|
46
|
+
} else if (data.e == "getcomp") {
|
|
47
|
+
_data.payload = _comps[data.payload];
|
|
48
|
+
} else if (data.e == "getview") {
|
|
49
|
+
_data.payload = _views[data.payload];
|
|
50
|
+
} else if (data.e == "request") {
|
|
51
|
+
try {
|
|
52
|
+
let pata = data.payload;
|
|
53
|
+
let __data = pata['data'];
|
|
54
|
+
let _body = pata['body'];
|
|
55
|
+
let res = await axios({
|
|
56
|
+
method: _body['method'].toString().toLowerCase(),
|
|
57
|
+
url: fcs.validURL(_body['path']) ? _body['path'] : (config.apis[_body['api'] ?? 0].baseURL + _body['path']),
|
|
58
|
+
data: __data ?? {},
|
|
59
|
+
headers: _body['headers'] ?? config.apis[_body['api'] ?? 0].headers
|
|
60
|
+
});
|
|
61
|
+
_data.payload = res.data;
|
|
62
|
+
if (ws.isSubscribed('/home/rat')) ws.send(JSON.stringify(_data), false, true);
|
|
63
|
+
|
|
64
|
+
} catch (e) {
|
|
65
|
+
_data.payload = { "code": 108, "error": e.message, "type": "RequestError" };
|
|
66
|
+
if (ws.isSubscribed('/home/rat')) ws.send(JSON.stringify(_data), false, true);
|
|
67
|
+
// ws.publish('/home/rat', JSON.stringify(_data));
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ws.publish('/home/rat', JSON.stringify(_data));
|
|
73
|
+
if (ws.isSubscribed('/home/rat')) ws.send(JSON.stringify(_data), false, true);
|
|
74
|
+
|
|
75
|
+
}
|
|
64
76
|
} catch (e) {
|
|
77
|
+
|
|
65
78
|
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
79
|
+
},
|
|
80
|
+
drain: (ws) => {
|
|
81
|
+
// console.log('WebSocket backpressure: ' + ws.getBufferedAmount());
|
|
82
|
+
},
|
|
83
|
+
close: (ws, code, message) => {
|
|
84
|
+
// console.log('WebSocket closed');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
}).get('/*', async (res, req) => {
|
|
88
|
+
let nodes = req.getUrl().split("/");
|
|
89
|
+
while (nodes[0] == "") nodes.shift();
|
|
90
|
+
let _nodes = JSON.parse(JSON.stringify(nodes));
|
|
91
|
+
let pubDir = `${process.cwd()}` + path.sep + `src`;
|
|
92
|
+
let filePath = "";
|
|
93
|
+
let errorPath = path.sep + '404.html';
|
|
94
|
+
if (nodes[0]) {
|
|
95
|
+
let last = nodes[nodes.length - 1];
|
|
96
|
+
while (_nodes.length) filePath += path.sep + _nodes.shift();
|
|
97
|
+
if (last.indexOf('.') > -1) {
|
|
98
|
+
filePath = fs.existsSync(pubDir + path.sep + filePath) ? filePath : errorPath;
|
|
99
|
+
} else {
|
|
100
|
+
if (!fs.existsSync(pubDir + path.sep + `views` + path.sep + nodes[0] + '.view')) {
|
|
101
|
+
filePath = errorPath;
|
|
102
|
+
} else {
|
|
103
|
+
filePath = path.sep + 'index.html';
|
|
104
|
+
}
|
|
71
105
|
}
|
|
106
|
+
} else filePath = path.sep + 'index.html';
|
|
107
|
+
|
|
108
|
+
// const mime = mime.lookup(pubDir + filePath) || 'application/octet-stream';
|
|
109
|
+
// // res.writeHeader('Content-Type', mime);
|
|
110
|
+
// const stream = fs.createReadStream(pubDir + filePath, { encoding: 'utf8' });
|
|
111
|
+
// stream.on('data', function (chunk) {
|
|
112
|
+
// console.log(chunk);
|
|
113
|
+
// });
|
|
114
|
+
// stream.on("error", () => {
|
|
115
|
+
// // error : file does not exist, etc.
|
|
116
|
+
// res.writeHeader("content-type", "text/plain");
|
|
117
|
+
// // res.statusCode = 404;
|
|
118
|
+
// res.end("ouuups, problem :/");
|
|
119
|
+
// });
|
|
120
|
+
|
|
121
|
+
// // res.writeHeader("content-type", mime);
|
|
122
|
+
// stream.on("open", () => {
|
|
123
|
+
// // good
|
|
124
|
+
// // mime is your font / file mime-type
|
|
125
|
+
// // res.statusCode = 200;
|
|
126
|
+
// stream.pipe(res);
|
|
127
|
+
// });
|
|
128
|
+
// res.end();
|
|
129
|
+
// return;
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
let readStream;
|
|
135
|
+
let paths = req.getUrl();
|
|
136
|
+
const acceptEncoding = req.getHeader('accept-encoding');
|
|
137
|
+
|
|
138
|
+
// at this point you need a way to get the requested file and catch errors if the file does not exist:
|
|
139
|
+
const fileName = pubDir + filePath; // i have some DANGEROUS_PATH_PATTERN test on the path var you must make sure it's safe
|
|
140
|
+
try {
|
|
141
|
+
readStream = toArrayBuffer(fs.readFileSync(fileName)); // toArrayBuffer is a function i got from examples
|
|
142
|
+
} catch (err) {
|
|
143
|
+
readStream = 'Error reading file.. or something';
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
readStream = toArrayBuffer(fs.readFileSync(fileName));
|
|
147
|
+
// setting headers and responding: res.aborted must be present
|
|
148
|
+
res.onAborted(() => {
|
|
149
|
+
res.aborted = true;
|
|
72
150
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
151
|
+
// write the headers and respond
|
|
152
|
+
// write the headers and respond
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
res.cork(() => {
|
|
156
|
+
const mimeT = mime.lookup(pubDir + filePath) || 'application/octet-stream';
|
|
157
|
+
res.writeHeader('Content-Type', mimeT);
|
|
158
|
+
// for (let i = 0; i < securityHeaders.length; i++) res.writeHeader(securityHeaders[i].name, securityHeaders[i].value);
|
|
159
|
+
if (!acceptEncoding) acceptEncoding = '';
|
|
160
|
+
if (/\bgzip\b/.test(acceptEncoding)) {
|
|
161
|
+
res.writeHeader('Content-Encoding', 'gzip');
|
|
162
|
+
readStream = zlib.gzipSync(readStream);
|
|
163
|
+
} else if (/\bdeflate\b/.test(acceptEncoding)) {
|
|
164
|
+
res.writeHeader('Content-Encoding', 'deflate');
|
|
165
|
+
readStream = zlib.deflateSync(readStream);
|
|
80
166
|
}
|
|
167
|
+
if (!res.aborted) res.end(readStream);
|
|
81
168
|
});
|
|
169
|
+
|
|
170
|
+
// const mimeType = mime.lookup(pubDir + filePath) || 'application/octet-stream';
|
|
171
|
+
|
|
172
|
+
// if (!res.aborted) {
|
|
173
|
+
// res.writeHeader('Content-Type', mimeType);
|
|
174
|
+
// res.end(fs.readFileSync(pubDir + filePath, "utf8"));
|
|
175
|
+
// }
|
|
176
|
+
return;
|
|
177
|
+
}).any('/*', (res, req) => {
|
|
178
|
+
res.end('Nothing to see here!');
|
|
179
|
+
}).listen(config.server.port * 1, (listenSocket) => {
|
|
180
|
+
if (listenSocket) {
|
|
181
|
+
// for automatic port selection use 0 as port above and we'll get one below this line.
|
|
182
|
+
// port = uws.us_socket_local_port(listenSocket);
|
|
183
|
+
// console.log('Listening to port ' + port);
|
|
184
|
+
console.log(`LumenJS server running at http://${config.server.host}:${config.server.port}/`);
|
|
185
|
+
_views = fcs.getAllFiles(`${process.cwd()}` + path.sep + `src` + path.sep + `views` + path.sep);
|
|
186
|
+
_comps = fcs.getAllFiles(`${process.cwd()}` + path.sep + `src` + path.sep + `comps` + path.sep);
|
|
187
|
+
} else {
|
|
188
|
+
console.log('Failed to run LumenJS server');
|
|
189
|
+
}
|
|
190
|
+
|
|
82
191
|
});
|
|
192
|
+
// app.use('/', express.static(`${process.cwd()}` + path.sep + `src`));
|
|
83
193
|
|
|
194
|
+
// io.on('connection', function (socket) {
|
|
195
|
+
// socket.on("request", async function (_data, _body, cb) {
|
|
196
|
+
// try {
|
|
197
|
+
// let res = await axios({
|
|
198
|
+
// method: _data['method'].toString().toLowerCase(),
|
|
199
|
+
// url: fcs.validURL(_data['path']) ? _data['path'] : (config.apis[_data['api'] ?? 0].baseURL + _data['path']),
|
|
200
|
+
// data: _body ?? {},
|
|
201
|
+
// headers: _data['headers'] ?? config.apis[_data['api'] ?? 0].headers
|
|
202
|
+
// });
|
|
203
|
+
// cb(res.data);
|
|
204
|
+
// } catch (e) {
|
|
205
|
+
// cb({ "code": 108, "error": e.message, "type": "RequestError" });
|
|
206
|
+
// }
|
|
207
|
+
// });
|
|
208
|
+
// socket.on("getview", function (msg, cb) {
|
|
209
|
+
// try {
|
|
210
|
+
// cb(_views[msg]);
|
|
211
|
+
// } catch (e) {
|
|
212
|
+
// }
|
|
213
|
+
// });
|
|
214
|
+
// socket.on("getcomp", function (msg, cb) {
|
|
215
|
+
// try {
|
|
216
|
+
// cb(_comps[msg]);
|
|
217
|
+
// } catch (e) {
|
|
218
|
+
// }
|
|
219
|
+
// });
|
|
220
|
+
// socket.on("getfiles", function (cb) {
|
|
221
|
+
// try {
|
|
222
|
+
// cb({
|
|
223
|
+
// "views": _views,
|
|
224
|
+
// "comps": _comps
|
|
225
|
+
// });
|
|
226
|
+
// } catch (e) {
|
|
227
|
+
// }
|
|
228
|
+
// });
|
|
229
|
+
// });
|
|
84
230
|
|
|
85
|
-
global.
|
|
86
|
-
global.
|
|
87
|
-
global.
|
|
88
|
-
global.fs = fs;
|
|
89
|
-
global.path = path;
|
|
231
|
+
// global.axios = axios;
|
|
232
|
+
// global.fs = fs;
|
|
233
|
+
// global.path = path;
|
|
90
234
|
|
|
91
|
-
var API = fcs.API;
|
|
92
|
-
global.API = API;
|
|
235
|
+
// var API = fcs.API;
|
|
236
|
+
// global.API = API;
|
|
93
237
|
|
|
94
|
-
if(fs.existsSync(`${process.cwd()}` + path.sep + `src` + path.sep + `app.js`)){
|
|
95
|
-
|
|
96
|
-
}
|
|
238
|
+
// if(fs.existsSync(`${process.cwd()}` + path.sep + `src` + path.sep + `app.js`)){
|
|
239
|
+
// require(`${process.cwd()}` + path.sep + `src` + path.sep + `app.js`);
|
|
240
|
+
// }
|
|
97
241
|
|
|
98
|
-
app.get('*', function (req, res) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
});
|
|
242
|
+
// app.get('*', function (req, res) {
|
|
243
|
+
// let nodes = req.params[0].split("/");
|
|
244
|
+
// if (nodes.length) nodes.shift();
|
|
245
|
+
// res.sendFile(`${process.cwd()}` + path.sep + `src` + path.sep + ((fs.existsSync(`${process.cwd()}` + path.sep + `src` + path.sep + `views` + path.sep + nodes[0] + `.view`)) ? 'index' : '404') + `.html`);
|
|
246
|
+
// return;
|
|
247
|
+
// });
|
|
104
248
|
|
|
105
|
-
app.post('*', function (req, res) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
});
|
|
249
|
+
// app.post('*', function (req, res) {
|
|
250
|
+
// let nodes = req.params[0].split("/");
|
|
251
|
+
// if (nodes.length) nodes.shift();
|
|
252
|
+
// res.sendFile(`${process.cwd()}` + path.sep + `src` + path.sep + ((fs.existsSync(`${process.cwd()}` + path.sep + `src` + path.sep + `views` + path.sep + nodes[0] + `.view`)) ? 'index' : '404') + `.html`);
|
|
253
|
+
// return;
|
|
254
|
+
// });
|
|
111
255
|
|
|
112
|
-
server.listen(config.server.port, function () {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
256
|
+
// server.listen(config.server.port, function () {
|
|
257
|
+
// console.log(`LumenJS server running at http://${config.server.host}:${config.server.port}/`);
|
|
258
|
+
// _views = fcs.getAllFiles(`${process.cwd()}` + path.sep + `src` + path.sep + `views` + path.sep);
|
|
259
|
+
// _comps = fcs.getAllFiles(`${process.cwd()}` + path.sep + `src` + path.sep + `comps` + path.sep);
|
|
260
|
+
// });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmjs/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "LumenJS is a tiny robust reactive javascript framework for building scalable and high-performant web applications and web user interfaces, be it simple or complex, with standard HTML, CSS and JavaScript",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -37,18 +37,14 @@
|
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"axios": "^0.27.2",
|
|
40
|
-
"compression": "^1.7.4",
|
|
41
|
-
"cookie-parser": "^1.4.6",
|
|
42
40
|
"cssnano": "^5.1.11",
|
|
43
|
-
"express": "^4.18.1",
|
|
44
|
-
"express-session": "^1.17.3",
|
|
45
41
|
"ftp-deploy": "^2.4.3",
|
|
46
42
|
"multer": "^1.4.5-lts.1",
|
|
47
43
|
"nodemon": "^2.0.16",
|
|
48
44
|
"ora": "^6.1.2",
|
|
49
45
|
"semver": "^7.3.7",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
46
|
+
"uglify-js": "^3.16.0",
|
|
47
|
+
"uWebSockets.js": "git://github.com/uNetworking/uWebSockets.js#v20.4.0"
|
|
52
48
|
},
|
|
53
49
|
"engines": {
|
|
54
50
|
"node": ">=12.0.0"
|
|
@@ -67,4 +63,4 @@
|
|
|
67
63
|
"type": "git",
|
|
68
64
|
"url": "git+https://github.com/bea-company/lmjs-cli.git"
|
|
69
65
|
}
|
|
70
|
-
}
|
|
66
|
+
}
|