@igea/oac_backend 1.0.1 → 1.0.2
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/package.json +3 -2
- package/src/config/development.json +4 -1
- package/src/config/production.json +4 -1
- package/src/controllers/health.js +18 -0
- package/src/index.js +34 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@igea/oac_backend",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Backend service for the OAC project",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"homepage": "https://github.com/chpigea/oac_backend#readme",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"axios": "1.10.0",
|
|
22
|
-
"express": "5.1.0"
|
|
22
|
+
"express": "5.1.0",
|
|
23
|
+
"get-port": "^7.1.0"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"cross-env": "^7.0.3",
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const express = require('express');
|
|
2
|
+
const router = express.Router();
|
|
3
|
+
const startDate = new Date()
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
router.get('/', (req, res) => {
|
|
7
|
+
|
|
8
|
+
let curDate = (new Date()).getTime()
|
|
9
|
+
|
|
10
|
+
res.json({
|
|
11
|
+
success: true,
|
|
12
|
+
running: Math.ceil((curDate - startDate.getTime())/1000),
|
|
13
|
+
started: startDate.toISOString()
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
module.exports = router
|
package/src/index.js
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const config = require('./config.js');
|
|
2
|
+
const express = require("express");
|
|
3
|
+
const axios = require("axios");
|
|
4
|
+
const getPort = require('get-port');
|
|
5
|
+
const serviceName = "backend"
|
|
6
|
+
|
|
7
|
+
const app = express();
|
|
8
|
+
app.use(express.json());
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
getPort.default({
|
|
12
|
+
port: getPort.portNumbers(config.port_range.min, config.port_range.max) }
|
|
13
|
+
).then((newPort)=>{
|
|
14
|
+
|
|
15
|
+
const healthRouter = require('./controllers/health.js');
|
|
16
|
+
app.use('/health', healthRouter);
|
|
17
|
+
|
|
18
|
+
app.listen(newPort, async () => {
|
|
19
|
+
console.log(`${serviceName} listening on port ${newPort}`);
|
|
20
|
+
try {
|
|
21
|
+
await axios.post(config.url_register, {
|
|
22
|
+
name: serviceName,
|
|
23
|
+
host: "localhost",
|
|
24
|
+
port: newPort
|
|
25
|
+
});
|
|
26
|
+
console.log(`Registered ${serviceName}`);
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.error(`Failed to register ${serviceName}: ${err.message}`);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
})
|
|
34
|
+
|