Skip to content

Commit c09ac24

Browse files
committed
ui api call is up and running
1 parent affdf26 commit c09ac24

40 files changed

+14991
-0
lines changed

.gitignore

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,51 @@ build/
4848

4949
### VS Code ###
5050
.vscode/
51+
52+
53+
### angular ###
54+
# compiled output
55+
/microservice-ui/dist
56+
/microservice-ui/tmp
57+
/microservice-ui/out-tsc
58+
# Only exists if Bazel was run
59+
/microservice-ui/bazel-out
60+
61+
# dependencies
62+
/microservice-ui/node_modules
63+
64+
# profiling files
65+
chrome-profiler-events*.json
66+
speed-measure-plugin*.json
67+
68+
# IDEs and editors
69+
/.idea
70+
.project
71+
.classpath
72+
.c9/
73+
*.launch
74+
.settings/
75+
*.sublime-workspace
76+
77+
# IDE - VSCode
78+
.vscode/*
79+
!.vscode/settings.json
80+
!.vscode/tasks.json
81+
!.vscode/launch.json
82+
!.vscode/extensions.json
83+
.history/*
84+
85+
# misc
86+
/microservice-ui/.sass-cache
87+
/microservice-ui/connect.lock
88+
/microservice-ui/coverage
89+
/microservice-ui/libpeerconnection.log
90+
npm-debug.log
91+
yarn-error.log
92+
testem.log
93+
/microservice-ui/typings
94+
95+
# System Files
96+
.DS_Store
97+
Thumbs.db
98+

microservice-ui/.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Editor configuration, see https://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
max_line_length = off
13+
trim_trailing_whitespace = false

microservice-ui/angular.json

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"microservice-ui": {
7+
"projectType": "application",
8+
"schematics": {},
9+
"root": "",
10+
"sourceRoot": "src",
11+
"prefix": "app",
12+
"architect": {
13+
"build": {
14+
"builder": "@angular-devkit/build-angular:browser",
15+
"options": {
16+
"outputPath": "dist/microservice-ui",
17+
"index": "src/index.html",
18+
"main": "src/main.ts",
19+
"polyfills": "src/polyfills.ts",
20+
"tsConfig": "tsconfig.app.json",
21+
"aot": false,
22+
"assets": [
23+
"src/favicon.ico",
24+
"src/assets"
25+
],
26+
"styles": [
27+
"src/styles.css",
28+
"node_modules/bootstrap/dist/css/bootstrap.min.css",
29+
"node_modules/font-awesome/css/font-awesome.min.css"
30+
],
31+
"scripts": []
32+
},
33+
"configurations": {
34+
"production": {
35+
"fileReplacements": [
36+
{
37+
"replace": "src/environments/environment.ts",
38+
"with": "src/environments/environment.prod.ts"
39+
}
40+
],
41+
"optimization": true,
42+
"outputHashing": "all",
43+
"sourceMap": false,
44+
"extractCss": true,
45+
"namedChunks": false,
46+
"aot": true,
47+
"extractLicenses": true,
48+
"vendorChunk": false,
49+
"buildOptimizer": true,
50+
"budgets": [
51+
{
52+
"type": "initial",
53+
"maximumWarning": "2mb",
54+
"maximumError": "5mb"
55+
},
56+
{
57+
"type": "anyComponentStyle",
58+
"maximumWarning": "6kb",
59+
"maximumError": "10kb"
60+
}
61+
]
62+
}
63+
}
64+
},
65+
"serve": {
66+
"builder": "@angular-devkit/build-angular:dev-server",
67+
"options": {
68+
"browserTarget": "microservice-ui:build"
69+
},
70+
"configurations": {
71+
"production": {
72+
"browserTarget": "microservice-ui:build:production"
73+
}
74+
}
75+
},
76+
"extract-i18n": {
77+
"builder": "@angular-devkit/build-angular:extract-i18n",
78+
"options": {
79+
"browserTarget": "microservice-ui:build"
80+
}
81+
},
82+
"test": {
83+
"builder": "@angular-devkit/build-angular:karma",
84+
"options": {
85+
"main": "src/test.ts",
86+
"polyfills": "src/polyfills.ts",
87+
"tsConfig": "tsconfig.spec.json",
88+
"karmaConfig": "karma.conf.js",
89+
"assets": [
90+
"src/favicon.ico",
91+
"src/assets"
92+
],
93+
"styles": [
94+
"src/styles.css"
95+
],
96+
"scripts": []
97+
}
98+
},
99+
"lint": {
100+
"builder": "@angular-devkit/build-angular:tslint",
101+
"options": {
102+
"tsConfig": [
103+
"tsconfig.app.json",
104+
"tsconfig.spec.json",
105+
"e2e/tsconfig.json"
106+
],
107+
"exclude": [
108+
"**/node_modules/**"
109+
]
110+
}
111+
},
112+
"e2e": {
113+
"builder": "@angular-devkit/build-angular:protractor",
114+
"options": {
115+
"protractorConfig": "e2e/protractor.conf.js",
116+
"devServerTarget": "microservice-ui:serve"
117+
},
118+
"configurations": {
119+
"production": {
120+
"devServerTarget": "microservice-ui:serve:production"
121+
}
122+
}
123+
}
124+
}
125+
}},
126+
"defaultProject": "microservice-ui"
127+
}

microservice-ui/authMiddleware.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const jwt = require("jsonwebtoken");
2+
const APP_SECRET = "myappsecret";
3+
const USERNAME = "admin";
4+
const PASSWORD = "secret";
5+
6+
module.exports = function (req, res, next) {
7+
if ((req.url == "/api/login" || req.url == "/login") && req.method == "POST") {
8+
if (req.body != null && req.body.name == USERNAME && req.body.password == PASSWORD) {
9+
let token = jwt.sign({ data: USERNAME, expiresIn: "1h" }, APP_SECRET);
10+
res.json({ success: true, token: token });
11+
} else {
12+
res.json({ success: false });
13+
}
14+
res.end();
15+
return;
16+
} else if ((((req.url.startsWith("/api/products") || req.url.startsWith("/products"))
17+
|| (req.url.startsWith("/api/categories") || req.url.startsWith("/categories"))) && req.method != "GET")
18+
|| ((req.url.startsWith("/api/orders") || req.url.startsWith("/orders")) && req.method != "POST")) {
19+
let token = req.headers["authorization"];
20+
if (token != null && token.startsWith("Bearer<")) {
21+
token = token.substring(7, token.length - 1);
22+
try {
23+
jwt.verify(token, APP_SECRET);
24+
next();
25+
return;
26+
} catch (err) { }
27+
}
28+
res.statusCode = 401;
29+
res.end();
30+
return;
31+
}
32+
33+
next();
34+
}

microservice-ui/browserslist

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2+
# For additional information regarding the format and rule options, please see:
3+
# https://github.com/browserslist/browserslist#queries
4+
5+
# You can see what browsers were selected by your queries by running:
6+
# npx browserslist
7+
8+
> 0.5%
9+
last 2 versions
10+
Firefox ESR
11+
not dead
12+
not IE 9-11 # For IE 9-11 support, remove 'not'.

microservice-ui/data.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = function () {
2+
return {
3+
products: [
4+
{
5+
id: 1,
6+
productCode: "TW1",
7+
productTitle: "Titan Watch",
8+
imageUrl: "titan.png",
9+
discountOffer: null
10+
},
11+
{
12+
id: 2,
13+
productCode: "FTW1",
14+
productTitle: "FastTrack Watch",
15+
imageUrl: "fasttrack.png",
16+
discountOffer: 20
17+
},
18+
{
19+
id: 3,
20+
productCode: "RW1",
21+
productTitle: "Rolex Watch",
22+
imageUrl: "rolex.png",
23+
discountOffer: null
24+
}
25+
],
26+
orders: []
27+
}
28+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// @ts-check
2+
// Protractor configuration file, see link for more information
3+
// https://github.com/angular/protractor/blob/master/lib/config.ts
4+
5+
const { SpecReporter } = require('jasmine-spec-reporter');
6+
7+
/**
8+
* @type { import("protractor").Config }
9+
*/
10+
exports.config = {
11+
allScriptsTimeout: 11000,
12+
specs: [
13+
'./src/**/*.e2e-spec.ts'
14+
],
15+
capabilities: {
16+
browserName: 'chrome'
17+
},
18+
directConnect: true,
19+
baseUrl: 'http://localhost:4200/',
20+
framework: 'jasmine',
21+
jasmineNodeOpts: {
22+
showColors: true,
23+
defaultTimeoutInterval: 30000,
24+
print: function() {}
25+
},
26+
onPrepare() {
27+
require('ts-node').register({
28+
project: require('path').join(__dirname, './tsconfig.json')
29+
});
30+
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
31+
}
32+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { AppPage } from './app.po';
2+
import { browser, logging } from 'protractor';
3+
4+
describe('workspace-project App', () => {
5+
let page: AppPage;
6+
7+
beforeEach(() => {
8+
page = new AppPage();
9+
});
10+
11+
it('should display welcome message', () => {
12+
page.navigateTo();
13+
expect(page.getTitleText()).toEqual('microservice-ui app is running!');
14+
});
15+
16+
afterEach(async () => {
17+
// Assert that there are no errors emitted from the browser
18+
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
19+
expect(logs).not.toContain(jasmine.objectContaining({
20+
level: logging.Level.SEVERE,
21+
} as logging.Entry));
22+
});
23+
});

microservice-ui/e2e/src/app.po.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { browser, by, element } from 'protractor';
2+
3+
export class AppPage {
4+
navigateTo() {
5+
return browser.get(browser.baseUrl) as Promise<any>;
6+
}
7+
8+
getTitleText() {
9+
return element(by.css('app-root .content span')).getText() as Promise<string>;
10+
}
11+
}

microservice-ui/e2e/tsconfig.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../out-tsc/e2e",
5+
"module": "commonjs",
6+
"target": "es5",
7+
"types": [
8+
"jasmine",
9+
"jasminewd2",
10+
"node"
11+
]
12+
}
13+
}

0 commit comments

Comments
 (0)