aionix 1.0.2 → 1.0.4
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/bin/aionix.cmd +3 -0
- package/package.json +5 -2
- package/server/app.js +18 -7
package/bin/aionix.cmd
ADDED
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aionix",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Offline Developer Toolkit - Learning, Tools & Productivity",
|
|
5
5
|
"main": "server/app.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"dev-ai": "bin/index.js",
|
|
8
|
-
"aionix": "./bin/
|
|
8
|
+
"aionix": "./bin/aionix.cmd"
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"bin/",
|
|
@@ -28,5 +28,8 @@
|
|
|
28
28
|
"express": "^4.18.2",
|
|
29
29
|
"nedb-promises": "^6.2.1",
|
|
30
30
|
"open": "^8.4.2"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"start": "node ./bin/index.js"
|
|
31
34
|
}
|
|
32
35
|
}
|
package/server/app.js
CHANGED
|
@@ -3,6 +3,7 @@ const express = require('express');
|
|
|
3
3
|
const path = require('path');
|
|
4
4
|
const open = require('open');
|
|
5
5
|
const chalk = require('chalk');
|
|
6
|
+
const net = require('net');
|
|
6
7
|
|
|
7
8
|
const snippetsRoute = require('./routes/snippets');
|
|
8
9
|
const quizRoute = require('./routes/quiz');
|
|
@@ -10,26 +11,36 @@ const habitsRoute = require('./routes/habits');
|
|
|
10
11
|
const docsRoute = require('./routes/docs');
|
|
11
12
|
|
|
12
13
|
const app = express();
|
|
13
|
-
const PORT = 3000;
|
|
14
14
|
|
|
15
15
|
app.use(express.json());
|
|
16
16
|
app.use(express.static(path.join(__dirname, '../client')));
|
|
17
17
|
|
|
18
|
-
// Routes
|
|
19
18
|
app.use('/api/snippets', snippetsRoute);
|
|
20
19
|
app.use('/api/quiz', quizRoute);
|
|
21
20
|
app.use('/api/habits', habitsRoute);
|
|
22
21
|
app.use('/api/docs', docsRoute);
|
|
23
22
|
|
|
24
|
-
// Main page
|
|
25
23
|
app.get('/', (req, res) => {
|
|
26
24
|
res.sendFile(path.join(__dirname, '../client/index.html'));
|
|
27
25
|
});
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
// Auto find available port
|
|
28
|
+
function getPort(start) {
|
|
29
|
+
return new Promise((resolve) => {
|
|
30
|
+
const server = net.createServer();
|
|
31
|
+
server.listen(start, () => {
|
|
32
|
+
server.close(() => resolve(start));
|
|
33
|
+
});
|
|
34
|
+
server.on('error', () => resolve(getPort(start + 1)));
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getPort(3000).then(PORT => {
|
|
39
|
+
app.listen(PORT, async () => {
|
|
40
|
+
console.log(chalk.green(`✅ Server running at http://localhost:${PORT}`));
|
|
41
|
+
console.log(chalk.yellow('Opening browser...'));
|
|
42
|
+
await open(`http://localhost:${PORT}`);
|
|
43
|
+
});
|
|
33
44
|
});
|
|
34
45
|
|
|
35
46
|
module.exports = app;
|