fixed jsonpath #4
10 changed files with 39 additions and 38 deletions
|
@ -1,9 +1,9 @@
|
||||||
FROM node:alpine
|
FROM node:alpine
|
||||||
|
|
||||||
COPY dist/grafana-statuspage /grafana-statuspage
|
COPY dist/universal-statuspage /universal-statuspage
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
EXPOSE 4000
|
EXPOSE 4000
|
||||||
|
|
||||||
ENTRYPOINT ["node", "/grafana-statuspage/server/main.js"]
|
ENTRYPOINT ["node", "/universal-statuspage/server/main.js"]
|
||||||
|
|
30
angular.json
30
angular.json
|
@ -3,7 +3,7 @@
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"newProjectRoot": "projects",
|
"newProjectRoot": "projects",
|
||||||
"projects": {
|
"projects": {
|
||||||
"grafana-statuspage": {
|
"universal-statuspage": {
|
||||||
"projectType": "application",
|
"projectType": "application",
|
||||||
"schematics": {
|
"schematics": {
|
||||||
"@schematics/angular:component": {
|
"@schematics/angular:component": {
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
"build": {
|
"build": {
|
||||||
"builder": "@angular-devkit/build-angular:browser",
|
"builder": "@angular-devkit/build-angular:browser",
|
||||||
"options": {
|
"options": {
|
||||||
"outputPath": "dist/grafana-statuspage/browser",
|
"outputPath": "dist/universal-statuspage/browser",
|
||||||
"index": "src/index.html",
|
"index": "src/index.html",
|
||||||
"main": "src/main.ts",
|
"main": "src/main.ts",
|
||||||
"polyfills": "src/polyfills.ts",
|
"polyfills": "src/polyfills.ts",
|
||||||
|
@ -69,18 +69,18 @@
|
||||||
"serve": {
|
"serve": {
|
||||||
"builder": "@angular-devkit/build-angular:dev-server",
|
"builder": "@angular-devkit/build-angular:dev-server",
|
||||||
"options": {
|
"options": {
|
||||||
"browserTarget": "grafana-statuspage:build"
|
"browserTarget": "universal-statuspage:build"
|
||||||
},
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"production": {
|
"production": {
|
||||||
"browserTarget": "grafana-statuspage:build:production"
|
"browserTarget": "universal-statuspage:build:production"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"extract-i18n": {
|
"extract-i18n": {
|
||||||
"builder": "@angular-devkit/build-angular:extract-i18n",
|
"builder": "@angular-devkit/build-angular:extract-i18n",
|
||||||
"options": {
|
"options": {
|
||||||
"browserTarget": "grafana-statuspage:build"
|
"browserTarget": "universal-statuspage:build"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"test": {
|
"test": {
|
||||||
|
@ -120,18 +120,18 @@
|
||||||
"builder": "@angular-devkit/build-angular:protractor",
|
"builder": "@angular-devkit/build-angular:protractor",
|
||||||
"options": {
|
"options": {
|
||||||
"protractorConfig": "e2e/protractor.conf.js",
|
"protractorConfig": "e2e/protractor.conf.js",
|
||||||
"devServerTarget": "grafana-statuspage:serve"
|
"devServerTarget": "universal-statuspage:serve"
|
||||||
},
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"production": {
|
"production": {
|
||||||
"devServerTarget": "grafana-statuspage:serve:production"
|
"devServerTarget": "universal-statuspage:serve:production"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"server": {
|
"server": {
|
||||||
"builder": "@angular-devkit/build-angular:server",
|
"builder": "@angular-devkit/build-angular:server",
|
||||||
"options": {
|
"options": {
|
||||||
"outputPath": "dist/grafana-statuspage/server",
|
"outputPath": "dist/universal-statuspage/server",
|
||||||
"main": "server.ts",
|
"main": "server.ts",
|
||||||
"tsConfig": "tsconfig.server.json"
|
"tsConfig": "tsconfig.server.json"
|
||||||
},
|
},
|
||||||
|
@ -152,21 +152,21 @@
|
||||||
"serve-ssr": {
|
"serve-ssr": {
|
||||||
"builder": "@nguniversal/builders:ssr-dev-server",
|
"builder": "@nguniversal/builders:ssr-dev-server",
|
||||||
"options": {
|
"options": {
|
||||||
"browserTarget": "grafana-statuspage:build",
|
"browserTarget": "universal-statuspage:build",
|
||||||
"serverTarget": "grafana-statuspage:server"
|
"serverTarget": "universal-statuspage:server"
|
||||||
},
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
"production": {
|
"production": {
|
||||||
"browserTarget": "grafana-statuspage:build:production",
|
"browserTarget": "universal-statuspage:build:production",
|
||||||
"serverTarget": "grafana-statuspage:server:production"
|
"serverTarget": "universal-statuspage:server:production"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"prerender": {
|
"prerender": {
|
||||||
"builder": "@nguniversal/builders:prerender",
|
"builder": "@nguniversal/builders:prerender",
|
||||||
"options": {
|
"options": {
|
||||||
"browserTarget": "grafana-statuspage:build:production",
|
"browserTarget": "universal-statuspage:build:production",
|
||||||
"serverTarget": "grafana-statuspage:server:production",
|
"serverTarget": "universal-statuspage:server:production",
|
||||||
"routes": [
|
"routes": [
|
||||||
"/"
|
"/"
|
||||||
]
|
]
|
||||||
|
@ -177,5 +177,5 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
"defaultProject": "grafana-statuspage"
|
"defaultProject": "universal-statuspage"
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ describe('workspace-project App', () => {
|
||||||
|
|
||||||
it('should display welcome message', () => {
|
it('should display welcome message', () => {
|
||||||
page.navigateTo();
|
page.navigateTo();
|
||||||
expect(page.getTitleText()).toEqual('grafana-statuspage app is running!');
|
expect(page.getTitleText()).toEqual('universal-statuspage app is running!');
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
|
|
@ -16,7 +16,7 @@ module.exports = function (config) {
|
||||||
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
||||||
},
|
},
|
||||||
coverageIstanbulReporter: {
|
coverageIstanbulReporter: {
|
||||||
dir: require('path').join(__dirname, './coverage/grafana-statuspage'),
|
dir: require('path').join(__dirname, './coverage/universal-statuspage'),
|
||||||
reports: ['html', 'lcovonly', 'text-summary'],
|
reports: ['html', 'lcovonly', 'text-summary'],
|
||||||
fixWebpackSourcePaths: true
|
fixWebpackSourcePaths: true
|
||||||
},
|
},
|
||||||
|
|
12
package.json
12
package.json
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "grafana-statuspage",
|
"name": "universal-statuspage",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
|
@ -8,10 +8,10 @@
|
||||||
"test": "ng test",
|
"test": "ng test",
|
||||||
"lint": "ng lint",
|
"lint": "ng lint",
|
||||||
"e2e": "ng e2e",
|
"e2e": "ng e2e",
|
||||||
"dev:ssr": "ng run grafana-statuspage:serve-ssr",
|
"dev:ssr": "ng run universal-statuspage:serve-ssr",
|
||||||
"serve:ssr": "node dist/grafana-statuspage/server/main.js",
|
"serve:ssr": "node dist/universal-statuspage/server/main.js",
|
||||||
"build:ssr": "ng build --prod && ng run grafana-statuspage:server:production",
|
"build:ssr": "ng build --prod && ng run universal-statuspage:server:production",
|
||||||
"prerender": "ng run grafana-statuspage:prerender"
|
"prerender": "ng run universal-statuspage:prerender"
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
"@nguniversal/express-engine": "^10.0.1",
|
"@nguniversal/express-engine": "^10.0.1",
|
||||||
"bootstrap": "^4.5.0",
|
"bootstrap": "^4.5.0",
|
||||||
"express": "^4.15.2",
|
"express": "^4.15.2",
|
||||||
"jsonpath": "^1.0.2",
|
"jsonpath-plus": "^4.0.0",
|
||||||
"roboto-fontface": "^0.10.0",
|
"roboto-fontface": "^0.10.0",
|
||||||
"rxjs": "~6.6.0",
|
"rxjs": "~6.6.0",
|
||||||
"tslib": "^2.0.0",
|
"tslib": "^2.0.0",
|
||||||
|
|
|
@ -8,12 +8,12 @@ import {AppServerModule} from './src/main.server';
|
||||||
import {APP_BASE_HREF} from '@angular/common';
|
import {APP_BASE_HREF} from '@angular/common';
|
||||||
import {existsSync} from 'fs';
|
import {existsSync} from 'fs';
|
||||||
import {api} from './src/main.status';
|
import {api} from './src/main.status';
|
||||||
import {environment} from "./src/environments/environment";
|
import {environment} from './src/environments/environment';
|
||||||
|
|
||||||
// The Express app is exported so that it can be used by serverless Functions.
|
// The Express app is exported so that it can be used by serverless Functions.
|
||||||
export function app() {
|
export function app() {
|
||||||
const server = express();
|
const server = express();
|
||||||
const distFolder = environment.production ? '/grafana-statuspage/browser' : join(process.cwd(), 'dist/grafana-statuspage/browser');
|
const distFolder = environment.production ? '/universal-statuspage/browser' : join(process.cwd(), 'dist/universal-statuspage/browser');
|
||||||
const indexHtml = existsSync(join(distFolder, 'index.original.html')) ? 'index.original.html' : 'index';
|
const indexHtml = existsSync(join(distFolder, 'index.original.html')) ? 'index.original.html' : 'index';
|
||||||
|
|
||||||
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
|
// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
|
||||||
|
|
|
@ -20,16 +20,16 @@ describe('AppComponent', () => {
|
||||||
expect(app).toBeTruthy();
|
expect(app).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should have as title 'grafana-statuspage'`, () => {
|
it(`should have as title 'universal-statuspage'`, () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
const app = fixture.componentInstance;
|
const app = fixture.componentInstance;
|
||||||
expect(app.title).toEqual('grafana-statuspage');
|
expect(app.title).toEqual('universal-statuspage');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render title', () => {
|
it('should render title', () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
const compiled = fixture.nativeElement;
|
const compiled = fixture.nativeElement;
|
||||||
expect(compiled.querySelector('.content span').textContent).toContain('grafana-statuspage app is running!');
|
expect(compiled.querySelector('.content span').textContent).toContain('universal-statuspage app is running!');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>grafana-statuspage</title>
|
<title>universal-statuspage</title>
|
||||||
<base href="/">
|
<base href="/">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link id="favicon" rel="icon" type="image/x-icon" href="">
|
<link id="favicon" rel="icon" type="image/x-icon" href="">
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import {json, Router} from 'express';
|
import {json, Router} from 'express';
|
||||||
import {CurrentStatus, State} from './app/_data/data';
|
import {CurrentStatus, State} from './app/_data/data';
|
||||||
import {existsSync, readFileSync, writeFileSync} from 'fs';
|
import {existsSync, readFileSync, writeFileSync} from 'fs';
|
||||||
import * as jp from 'jsonpath';
|
import {join} from 'path';
|
||||||
|
import {JSONPath} from 'jsonpath-plus';
|
||||||
|
|
||||||
interface Cache {
|
interface Cache {
|
||||||
[id: string]: State;
|
[id: string]: State;
|
||||||
|
@ -43,7 +44,8 @@ interface StateKey {
|
||||||
const api = Router();
|
const api = Router();
|
||||||
api.use(json());
|
api.use(json());
|
||||||
|
|
||||||
const config = JSON.parse(readFileSync('config.json', {encoding: 'utf-8'})) as Config;
|
const serviceStates = existsSync(join(process.cwd(), 'cache.json')) ? JSON.parse(readFileSync(join(process.cwd(), 'cache.json'), {encoding: 'utf-8'})) : {} as Cache;
|
||||||
|
const config = JSON.parse(readFileSync(join(process.cwd(), 'config.json'), {encoding: 'utf-8'})) as Config;
|
||||||
const stateKeys: { [service: string]: StateKey } = config.groups
|
const stateKeys: { [service: string]: StateKey } = config.groups
|
||||||
.map(g => g.services).reduce((x, y) => x.concat(y), [])
|
.map(g => g.services).reduce((x, y) => x.concat(y), [])
|
||||||
.reduce((services, service) => {
|
.reduce((services, service) => {
|
||||||
|
@ -56,7 +58,6 @@ const stateKeys: { [service: string]: StateKey } = config.groups
|
||||||
};
|
};
|
||||||
return services;
|
return services;
|
||||||
}, {});
|
}, {});
|
||||||
const serviceStates = existsSync('cache.json') ? JSON.parse(readFileSync('cache.json', {encoding: 'utf-8'})) : {} as Cache;
|
|
||||||
|
|
||||||
let cache: CurrentStatus;
|
let cache: CurrentStatus;
|
||||||
updateCache();
|
updateCache();
|
||||||
|
@ -68,7 +69,7 @@ api.post('/update/health', (req, res) => {
|
||||||
}
|
}
|
||||||
const serviceId = req.query.service as string;
|
const serviceId = req.query.service as string;
|
||||||
const keys = stateKeys[serviceId];
|
const keys = stateKeys[serviceId];
|
||||||
const state = jp.value(req.body, keys.statePath);
|
const state = JSONPath({path: keys.statePath, json: req.body, wrap: false});
|
||||||
|
|
||||||
if (keys.stateValues.operational.includes(state)) {
|
if (keys.stateValues.operational.includes(state)) {
|
||||||
serviceStates[serviceId] = 'operational';
|
serviceStates[serviceId] = 'operational';
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
"outDir": "./out-tsc/app-server",
|
"outDir": "./out-tsc/app-server",
|
||||||
"types": [
|
"types": [
|
||||||
"node"
|
"node"
|
||||||
]
|
],
|
||||||
, "target": "es2016"
|
"target": "es2016"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src/main.server.ts",
|
"src/main.server.ts",
|
||||||
"server.ts"
|
"server.ts"
|
||||||
|
|
Reference in a new issue