@igea/oac_frontend 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/.github/workflows/npm-publish.yml +90 -0
- package/README.md +2 -0
- package/package.json +30 -0
- package/src/config/development.json +7 -0
- package/src/config/production.json +7 -0
- package/src/config.js +13 -0
- package/src/controllers/health.js +18 -0
- package/src/index.js +40 -0
- package/src/models/readme.md +0 -0
- package/src/views/base.twig +9 -0
- package/test/readme.md +0 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
name: Node.js CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main ]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: write
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
checker:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- name: Check if NPM_TOKEN is available
|
|
17
|
+
run: |
|
|
18
|
+
if [ -z "${{secrets.NPM_TOKEN}}" ]; then
|
|
19
|
+
echo "NPM_TOKEN is NOT set => ${{secrets.NPM_TOKEN}}"
|
|
20
|
+
exit 1
|
|
21
|
+
else
|
|
22
|
+
echo "NPM_TOKEN is set => ${{secrets.NPM_TOKEN}}"
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
build:
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
|
|
28
|
+
strategy:
|
|
29
|
+
matrix:
|
|
30
|
+
node-version: [23.x]
|
|
31
|
+
|
|
32
|
+
steps:
|
|
33
|
+
- uses: actions/checkout@v3
|
|
34
|
+
|
|
35
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
36
|
+
uses: actions/setup-node@v3
|
|
37
|
+
with:
|
|
38
|
+
node-version: ${{ matrix.node-version }}
|
|
39
|
+
cache: 'npm'
|
|
40
|
+
|
|
41
|
+
- name: Install dependencies
|
|
42
|
+
run: npm ci
|
|
43
|
+
|
|
44
|
+
#- name: Run tests
|
|
45
|
+
# run: npm test
|
|
46
|
+
|
|
47
|
+
publish-npm:
|
|
48
|
+
needs: build
|
|
49
|
+
runs-on: ubuntu-latest
|
|
50
|
+
if: github.ref == 'refs/heads/main'
|
|
51
|
+
steps:
|
|
52
|
+
- uses: actions/checkout@v3
|
|
53
|
+
|
|
54
|
+
- name: Use Node.js
|
|
55
|
+
uses: actions/setup-node@v3
|
|
56
|
+
with:
|
|
57
|
+
node-version: 23.x
|
|
58
|
+
cache: 'npm'
|
|
59
|
+
|
|
60
|
+
- name: Install dependencies
|
|
61
|
+
run: npm ci
|
|
62
|
+
|
|
63
|
+
- name: Configure Git identity
|
|
64
|
+
run: |
|
|
65
|
+
git config user.name "github-actions[bot]"
|
|
66
|
+
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
67
|
+
|
|
68
|
+
- name: Bump version
|
|
69
|
+
run: npm version patch -m "ci:bump version to %s [skip ci]"
|
|
70
|
+
|
|
71
|
+
- name: Use NPM Token
|
|
72
|
+
uses: dkershner6/use-npm-token-action@v2
|
|
73
|
+
with:
|
|
74
|
+
token: ${{ secrets.NPM_TOKEN }}
|
|
75
|
+
|
|
76
|
+
- name: Show whoami to confirm auth
|
|
77
|
+
run: npm whoami
|
|
78
|
+
|
|
79
|
+
- name: Publish to npm
|
|
80
|
+
run: npm publish --access public
|
|
81
|
+
env:
|
|
82
|
+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
|
83
|
+
|
|
84
|
+
- name: Push changes
|
|
85
|
+
uses: ad-m/github-push-action@v0.6.0
|
|
86
|
+
with:
|
|
87
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
88
|
+
branch: main
|
|
89
|
+
tags: true
|
|
90
|
+
|
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@igea/oac_frontend",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Frontend service for the OAC project",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "cross-env NODE_ENV=production node src/index.js",
|
|
8
|
+
"dev": "cross-env NODE_ENV=development nodemon src/index.js"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/chpigea/oac_frontend.git"
|
|
13
|
+
},
|
|
14
|
+
"author": "Christian R. Picone",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/chpigea/oac_frontend/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/chpigea/oac_frontend#readme",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"axios": "1.10.0",
|
|
22
|
+
"express": "5.1.0",
|
|
23
|
+
"get-port": "7.1.0",
|
|
24
|
+
"twig": "1.17.1"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"cross-env": "7.0.3",
|
|
28
|
+
"nodemon": "3.1.10"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/config.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// config.js
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
|
|
5
|
+
function loadConfig() {
|
|
6
|
+
const env = process.env.NODE_ENV || 'development';
|
|
7
|
+
const configFolder = process.env.OAC_CONFIG_FOLDER || __dirname;
|
|
8
|
+
const configPath = path.join(configFolder, 'config', `${env}.json`);
|
|
9
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
10
|
+
return config;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = loadConfig();
|
|
@@ -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
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const config = require('./config.js');
|
|
2
|
+
const express = require("express");
|
|
3
|
+
const axios = require("axios");
|
|
4
|
+
const getPort = require('get-port');
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const serviceName = "frontend"
|
|
7
|
+
|
|
8
|
+
const app = express();
|
|
9
|
+
app.use(express.json());
|
|
10
|
+
app.set('view engine', 'twig');
|
|
11
|
+
app.set('views', path.join(__dirname, 'views'));
|
|
12
|
+
|
|
13
|
+
getPort.default({
|
|
14
|
+
port: getPort.portNumbers(config.port_range.min, config.port_range.max) }
|
|
15
|
+
).then((newPort)=>{
|
|
16
|
+
|
|
17
|
+
const healthRouter = require('./controllers/health.js');
|
|
18
|
+
app.use('/health', healthRouter);
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
app.get('/', (req, res) => {
|
|
22
|
+
res.render('base', { title: 'Home Page', message: 'Hello from Twig!' });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
app.listen(newPort, async () => {
|
|
26
|
+
console.log(`${serviceName} listening on port ${newPort}`);
|
|
27
|
+
try {
|
|
28
|
+
await axios.post(config.url_register, {
|
|
29
|
+
name: serviceName,
|
|
30
|
+
host: "localhost",
|
|
31
|
+
port: newPort
|
|
32
|
+
});
|
|
33
|
+
console.log(`Registered ${serviceName}`);
|
|
34
|
+
} catch (err) {
|
|
35
|
+
console.error(`Failed to register ${serviceName}: ${err.message}`);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
})
|
|
40
|
+
|
|
File without changes
|
package/test/readme.md
ADDED
|
File without changes
|