├── .github └── FUNDING.yml ├── src ├── app │ ├── app-shell │ │ ├── app-shell.component.css │ │ ├── app-shell.component.html │ │ ├── app-shell.component.ts │ │ └── app-shell.component.spec.ts │ ├── shared │ │ ├── components │ │ │ ├── navbar │ │ │ │ ├── navbar.scss │ │ │ │ ├── navbar.html │ │ │ │ └── navbar.component.ts │ │ │ ├── footer │ │ │ │ ├── footer.html │ │ │ │ ├── footer.component.ts │ │ │ │ └── footer.scss │ │ │ ├── page-header │ │ │ │ ├── page-header.html │ │ │ │ └── page-header.component.ts │ │ │ └── components.ts │ │ └── shared.module.ts │ ├── app.component.html │ ├── pages │ │ ├── 404 │ │ │ └── not-found.component.ts │ │ ├── sw │ │ │ ├── sw.html │ │ │ ├── sw.scss │ │ │ └── sw.component.ts │ │ ├── home │ │ │ ├── home.html │ │ │ ├── home.scss │ │ │ └── home.component.ts │ │ ├── lazy │ │ │ ├── lazy.scss │ │ │ ├── lazy.routes.ts │ │ │ ├── actions │ │ │ │ └── page-num.actions.ts │ │ │ ├── reducers │ │ │ │ ├── page-num.reducers.ts │ │ │ │ └── index.ts │ │ │ ├── lazy.module.ts │ │ │ ├── lazy.html │ │ │ └── lazy.component.ts │ │ ├── profile │ │ │ └── profile.scss │ │ └── components.ts │ ├── core │ │ ├── services │ │ │ ├── auth-guard.service.ts │ │ │ ├── services.ts │ │ │ ├── example.service.ts │ │ │ ├── github.service.ts │ │ │ └── auth.service.ts │ │ ├── actions │ │ │ └── hello-example.actions.ts │ │ ├── module-import-guard.ts │ │ ├── core.module.ts │ │ └── reducers │ │ │ └── hello-example.reducers.ts │ ├── app.server.module.ts │ ├── app.component.scss │ ├── app.component.ts │ ├── app-routing.module.ts │ ├── app.module.ts │ └── reducers │ │ └── index.ts ├── favicon.png ├── assets │ ├── giphy.gif │ ├── favicon.png │ ├── icons │ │ ├── icon-72x72.png │ │ ├── icon-96x96.png │ │ ├── icon-128x128.png │ │ ├── icon-144x144.png │ │ ├── icon-152x152.png │ │ ├── icon-192x192.png │ │ ├── icon-384x384.png │ │ └── icon-512x512.png │ └── ring.svg ├── browserconfig.xml ├── tslint.json ├── manifest.webmanifest ├── environments │ ├── environment.prod.ts │ ├── environment.ts │ └── environment.hmr.ts ├── index.html ├── theme │ └── _theme.scss ├── main.server.ts ├── hmr.ts ├── test.ts ├── styles.scss ├── main.ts ├── _variables.scss └── polyfills.ts ├── .dockerignore ├── .snyk ├── static.paths.ts ├── servers ├── node-koa-js │ ├── nodemon.json │ ├── jshintignore │ ├── src │ │ ├── routes │ │ │ ├── controllers │ │ │ │ ├── keepAlive.js │ │ │ │ ├── secret.js │ │ │ │ ├── index.js │ │ │ │ └── auth.js │ │ │ ├── apis.js │ │ │ ├── keepAlive-router.js │ │ │ ├── secret-router.js │ │ │ ├── auth-router.js │ │ │ └── index.js │ │ ├── utils │ │ │ ├── errors.js │ │ │ └── jwt.js │ │ ├── middlewares │ │ │ ├── auth-required.js │ │ │ └── jwt.js │ │ ├── db.json │ │ ├── db.js │ │ ├── app.js │ │ ├── bin │ │ │ └── www │ │ └── config.js │ ├── pm2.json │ ├── .env │ ├── .env_prod │ └── package.json ├── node-express-js │ ├── nodemon.json │ ├── .jshintignore │ ├── .editorconfig │ ├── src │ │ ├── db.json │ │ ├── routes │ │ │ ├── apis.js │ │ │ └── controllers │ │ │ │ ├── keepalive.js │ │ │ │ └── secret.js │ │ ├── passport.js │ │ ├── db.js │ │ └── config.js │ ├── pm2.json │ ├── .env │ ├── .env_prod │ ├── package.json │ └── bin │ │ └── www └── node-express-ts │ ├── nodemon.json │ ├── .editorconfig │ ├── tsconfig.json │ ├── .env │ ├── .env_prod │ ├── src │ ├── routes │ │ ├── apis.ts │ │ └── controllers │ │ │ ├── keepalive.ts │ │ │ └── secret.ts │ ├── passport.ts │ ├── db.ts │ ├── util.ts │ └── server.ts │ ├── tslint.json │ └── package.json ├── proxy.conf.json ├── .prettierrc.json ├── tsconfig.app.json ├── e2e ├── protractor-ci.conf.js ├── src │ ├── app.po.ts │ └── app.e2e-spec.ts ├── tsconfig.json └── protractor.conf.js ├── tsconfig.spec.json ├── tsconfig.server.json ├── .editorconfig ├── travisci ├── install.sh ├── after_success.sh ├── script.sh ├── before_install.sh └── before_script.sh ├── browserslist ├── tsconfig.json ├── .codeclimate.yml ├── .prettierignore ├── CHANGELOG.md ├── Dockerfile ├── LICENSE ├── ngsw-config.json ├── .gitignore ├── webpack.server.config.js ├── tslint.json ├── .sass-lint.yml ├── .travis.yml ├── .circleci └── config.yml ├── prerender.ts ├── server.ts └── karma.conf.js /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [Ks89] 2 | -------------------------------------------------------------------------------- /src/app/app-shell/app-shell.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .git 3 | dist/ 4 | -------------------------------------------------------------------------------- /.snyk: -------------------------------------------------------------------------------- 1 | version: v1.5.2 2 | ignore: {} 3 | patch: {} 4 | -------------------------------------------------------------------------------- /static.paths.ts: -------------------------------------------------------------------------------- 1 | export const ROUTES = ['/', '/lazy']; 2 | -------------------------------------------------------------------------------- /src/app/app-shell/app-shell.component.html: -------------------------------------------------------------------------------- 1 |

2 | app-shell works! 3 |

4 | -------------------------------------------------------------------------------- /servers/node-koa-js/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "ignore": ["*.log"] 4 | } 5 | -------------------------------------------------------------------------------- /src/app/shared/components/navbar/navbar.scss: -------------------------------------------------------------------------------- 1 | .clickable { 2 | cursor: pointer; 3 | } 4 | -------------------------------------------------------------------------------- /src/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ks89/angular-cli-skeleton/HEAD/src/favicon.png -------------------------------------------------------------------------------- /servers/node-express-js/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "ignore": ["*.log"] 4 | } 5 | -------------------------------------------------------------------------------- /src/assets/giphy.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ks89/angular-cli-skeleton/HEAD/src/assets/giphy.gif -------------------------------------------------------------------------------- /servers/node-express-ts/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": true, 3 | "ignore": ["*.log", "**/dist"] 4 | } 5 | -------------------------------------------------------------------------------- /src/assets/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ks89/angular-cli-skeleton/HEAD/src/assets/favicon.png -------------------------------------------------------------------------------- /servers/node-express-js/.jshintignore: -------------------------------------------------------------------------------- 1 | bin 2 | docs 3 | node_modules 4 | public 5 | spec 6 | coverage 7 | .nyc_output 8 | -------------------------------------------------------------------------------- /servers/node-koa-js/jshintignore: -------------------------------------------------------------------------------- 1 | src/bin 2 | docs 3 | node_modules 4 | public 5 | spec 6 | coverage 7 | .nyc_output 8 | -------------------------------------------------------------------------------- /src/assets/icons/icon-72x72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ks89/angular-cli-skeleton/HEAD/src/assets/icons/icon-72x72.png -------------------------------------------------------------------------------- /src/assets/icons/icon-96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ks89/angular-cli-skeleton/HEAD/src/assets/icons/icon-96x96.png -------------------------------------------------------------------------------- /src/assets/icons/icon-128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ks89/angular-cli-skeleton/HEAD/src/assets/icons/icon-128x128.png -------------------------------------------------------------------------------- /src/assets/icons/icon-144x144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ks89/angular-cli-skeleton/HEAD/src/assets/icons/icon-144x144.png -------------------------------------------------------------------------------- /src/assets/icons/icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ks89/angular-cli-skeleton/HEAD/src/assets/icons/icon-152x152.png -------------------------------------------------------------------------------- /src/assets/icons/icon-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ks89/angular-cli-skeleton/HEAD/src/assets/icons/icon-192x192.png -------------------------------------------------------------------------------- /src/assets/icons/icon-384x384.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ks89/angular-cli-skeleton/HEAD/src/assets/icons/icon-384x384.png -------------------------------------------------------------------------------- /src/assets/icons/icon-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ks89/angular-cli-skeleton/HEAD/src/assets/icons/icon-512x512.png -------------------------------------------------------------------------------- /proxy.conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "/api": { 3 | "target": "http://localhost:3000", 4 | "secure": false, 5 | "logLevel": "debug" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/routes/controllers/keepAlive.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | async keepAlive(ctx) { 5 | ctx.body = { message: 'Koa is up!' }; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "bracketSpacing": true, 3 | "printWidth": 155, 4 | "semi": true, 5 | "singleQuote": true, 6 | "tabWidth": 2, 7 | "trailingComma": "none", 8 | "useTabs": false 9 | } 10 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/routes/controllers/secret.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | async getSecret(ctx) { 5 | ctx.body = { message: 'This is a secret message from an authenticated rest API' }; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": ["src/main.ts", "src/polyfills.ts"], 8 | "include": ["src/**/*.d.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /e2e/protractor-ci.conf.js: -------------------------------------------------------------------------------- 1 | const config = require('./protractor.conf').config; 2 | 3 | config.capabilities = { 4 | browserName: 'chrome', 5 | chromeOptions: { 6 | args: ['--no-sandbox'] 7 | } 8 | }; 9 | 10 | exports.config = config; 11 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/routes/apis.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | BASE_API_PATH: '/api', 5 | 6 | GET_KEEP_ALIVE: '/keepAlive', 7 | POST_LOGIN: '/login', 8 | GET_SECRET: '/secret', 9 | 10 | GET_LOGOUT: '/logout' 11 | }; 12 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getTitle() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/routes/controllers/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const secret = require('./secret'); 4 | const keepAlive = require('./keepAlive'); 5 | const auth = require('./auth'); 6 | 7 | module.exports = { 8 | secret, 9 | keepAlive, 10 | auth 11 | }; 12 | -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": ["jasmine", "node"] 6 | }, 7 | "files": ["src/test.ts", "src/polyfills.ts"], 8 | "include": ["src/**/*.spec.ts", "src/**/*.d.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /e2e/tsconfig.json: -------------------------------------------------------------------------------- 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 | } 14 | -------------------------------------------------------------------------------- /src/app/shared/components/footer/footer.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 10 |
11 | -------------------------------------------------------------------------------- /tsconfig.server.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.app.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app-server", 5 | "baseUrl": ".", 6 | "module": "commonjs" 7 | }, 8 | "angularCompilerOptions": { 9 | "entryModule": "app/app.server.module#AppServerModule" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://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 14 | -------------------------------------------------------------------------------- /servers/node-express-js/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://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 14 | -------------------------------------------------------------------------------- /servers/node-express-ts/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://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 14 | -------------------------------------------------------------------------------- /travisci/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Install - OS is $TRAVIS_OS_NAME" 4 | 5 | echo "Installing dependencies" 6 | if [[ $TRAVIS_OS_NAME = 'osx' ]]; then 7 | echo "Installing $TRAVIS_OS_NAME local dependencies" 8 | npm ci 9 | else 10 | echo "Installing $TRAVIS_OS_NAME local dependencies" 11 | npm ci 12 | fi 13 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |
6 |
7 | 8 |
9 | 10 |
11 | 12 |
13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/routes/keepAlive-router.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Router = require('koa-router'); 4 | const ctrl = require('./controllers').keepAlive; 5 | const router = new Router(); 6 | 7 | const APIS = require('./apis'); 8 | 9 | router.get(APIS.GET_KEEP_ALIVE, ctrl.keepAlive); 10 | 11 | module.exports = router.routes(); 12 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/utils/errors.js: -------------------------------------------------------------------------------- 1 | class UnauthorizedError extends Error {} 2 | class ForbiddenError extends Error {} 3 | class NotFoundError extends Error {} 4 | class ServerError extends Error {} 5 | 6 | module.exports = { 7 | UnauthorizedError, // 401 8 | ForbiddenError, // 403 9 | NotFoundError, // 404 10 | ServerError // 500 11 | }; 12 | -------------------------------------------------------------------------------- /src/app/app-shell/app-shell.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-app-shell', 5 | templateUrl: './app-shell.component.html', 6 | styleUrls: ['./app-shell.component.css'] 7 | }) 8 | export class AppShellComponent implements OnInit { 9 | constructor() {} 10 | 11 | ngOnInit() {} 12 | } 13 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/middlewares/auth-required.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const { UnauthorizedError } = require('../utils/errors'); 4 | 5 | module.exports = function(ctx, next) { 6 | console.log('auth middleware', ctx.state); 7 | if (!ctx.state.jwt || !ctx.state.jwt.id) { 8 | ctx.throw(401, new UnauthorizedError()); 9 | } 10 | return next(); 11 | }; 12 | -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('angular-cli-skeleton App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | // expect(page.getTitle()).toEqual('KS Welcome'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /servers/node-express-js/src/db.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "credential": { 4 | "id": 1, 5 | "username": "admin", 6 | "password": "password" 7 | }, 8 | "somethingelse": "" 9 | }, 10 | { 11 | "credential": { 12 | "id": 2, 13 | "username": "admin", 14 | "password": "admin" 15 | }, 16 | "somethingelse": "" 17 | } 18 | ] 19 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/db.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "credential": { 4 | "id": 1, 5 | "username": "admin", 6 | "password": "password" 7 | }, 8 | "somethingelse": "" 9 | }, 10 | { 11 | "credential": { 12 | "id": 2, 13 | "username": "admin", 14 | "password": "admin" 15 | }, 16 | "somethingelse": "" 17 | } 18 | ] 19 | -------------------------------------------------------------------------------- /src/app/shared/components/page-header/page-header.html: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /src/browserconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /travisci/after_success.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # build documentation 4 | echo "npm run docs on $TRAVIS_OS_NAME" 5 | npm run docs 6 | 7 | # send test coverage to codeclimate.com 8 | echo "npm run codeclimate on $TRAVIS_OS_NAME" 9 | npm run codeclimate 10 | 11 | # send test coverage to coveralls.io 12 | echo "npm run coveralls on $TRAVIS_OS_NAME" 13 | npm run coveralls 14 | -------------------------------------------------------------------------------- /servers/node-koa-js/pm2.json: -------------------------------------------------------------------------------- 1 | { 2 | "apps": [ 3 | { 4 | "name": "node-koa-server", 5 | "script": "src/bin/www", 6 | "exec_mode": "cluster", 7 | "instances": "max", 8 | "watch": false, 9 | "env_production": { 10 | "NODE_ENV": "production", 11 | "PORT": "80" 12 | }, 13 | "source_map_support": true 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /servers/node-express-js/pm2.json: -------------------------------------------------------------------------------- 1 | { 2 | "apps": [ 3 | { 4 | "name": "node-express-server", 5 | "script": "./bin/www", 6 | "exec_mode": "cluster", 7 | "instances": "max", 8 | "watch": false, 9 | "env_production": { 10 | "NODE_ENV": "production", 11 | "PORT": "80" 12 | }, 13 | "source_map_support": true 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/routes/secret-router.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Router = require('koa-router'); 4 | const ctrl = require('./controllers').secret; 5 | const router = new Router(); 6 | 7 | const APIS = require('./apis'); 8 | 9 | const auth = require('../middlewares/auth-required'); 10 | 11 | router.get(APIS.GET_SECRET, auth, ctrl.getSecret); 12 | 13 | module.exports = router.routes(); 14 | -------------------------------------------------------------------------------- /src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/routes/auth-router.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Router = require('koa-router'); 4 | const ctrl = require('./controllers').auth; 5 | const router = new Router(); 6 | 7 | const APIS = require('./apis'); 8 | 9 | const auth = require('../middlewares/auth-required'); 10 | 11 | router.post(APIS.POST_LOGIN, ctrl.login); 12 | 13 | router.get(APIS.GET_LOGOUT, auth, ctrl.logout); 14 | 15 | module.exports = router.routes(); 16 | -------------------------------------------------------------------------------- /servers/node-express-ts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "esModuleInterop": true, 5 | "target": "es6", 6 | "noImplicitAny": true, 7 | "moduleResolution": "node", 8 | "sourceMap": true, 9 | "outDir": "dist", 10 | "baseUrl": ".", 11 | "paths": { 12 | "*": ["node_modules/*"] 13 | }, 14 | "typeRoots": ["node_modules/@types"] 15 | }, 16 | "include": ["src/**/*"] 17 | } 18 | -------------------------------------------------------------------------------- /browserslist: -------------------------------------------------------------------------------- 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 | IE 11 13 | Firefox 67 14 | ios_saf >= 10 15 | Safari >= 10 16 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/routes/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Router = require('koa-router'); 4 | const router = new Router(); 5 | const api = new Router(); 6 | 7 | const APIS = require('./apis'); 8 | const keepAlive = require('./keepAlive-router'); 9 | const secret = require('./secret-router'); 10 | const auth = require('./auth-router'); 11 | 12 | api.use(keepAlive); 13 | api.use(secret); 14 | api.use(auth); 15 | 16 | router.use(APIS.BASE_API_PATH, api.routes()); 17 | 18 | module.exports = router; 19 | -------------------------------------------------------------------------------- /src/app/pages/sw/sw.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |

In this page I'm testing service workers :)

5 | 6 |
7 | 8 |
9 |

Response from github.com/users/Ks89:

10 |

Now try to shut down your internet connection, navigate to the homepage and go back here.

11 |

Can you see the same data also offline? It's magical!!!! :)

12 | {{githubUser | async | json}} 13 |
14 |
15 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/db.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const db = require('./db.json'); 4 | 5 | // Don't use a const here! 6 | // this is a private variable. 7 | // To access to 'tokens' use get, set and remove to prevent issues 8 | let tokens = []; 9 | 10 | function getTokens() { 11 | return tokens; 12 | } 13 | 14 | function setTokens(newTokens) { 15 | tokens = newTokens; 16 | } 17 | 18 | function removeTokens() { 19 | tokens = []; 20 | } 21 | 22 | module.exports = { 23 | getTokens: getTokens, 24 | setTokens: setTokens, 25 | removeTokens: removeTokens, 26 | db: db 27 | }; 28 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": ["node_modules/@types"], 15 | "lib": ["es2018", "dom"] 16 | }, 17 | "angularCompilerOptions": { 18 | "fullTemplateTypeCheck": true, 19 | "strictInjectionParameters": true 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/middlewares/jwt.js: -------------------------------------------------------------------------------- 1 | const koaJwt = require('koa-jwt'); 2 | const { JWT_SECRET } = require('../config'); 3 | 4 | module.exports = koaJwt({ 5 | getToken(ctx, opts) { 6 | const { authorization } = ctx.header; 7 | 8 | if (authorization && authorization.split(' ')[0] === 'Bearer') { 9 | return authorization.split(' ')[1]; 10 | } 11 | 12 | if (authorization && authorization.split(' ')[0] === 'Token') { 13 | return authorization.split(' ')[1]; 14 | } 15 | 16 | return null; 17 | }, 18 | secret: JWT_SECRET, 19 | passthrough: true, 20 | key: 'jwt' 21 | }); 22 | -------------------------------------------------------------------------------- /travisci/script.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # clean before the real production build 4 | npm run clean 5 | 6 | # run debug build 7 | echo "npm run debug build on $TRAVIS_OS_NAME" 8 | npm run build:dev 9 | 10 | # clean before the real production build 11 | npm run clean 12 | 13 | # run production build 14 | echo "npm run production build on $TRAVIS_OS_NAME" 15 | npm run build:prod 16 | 17 | # run production build + Server Side Rendering 18 | # echo "npm run production build + ssr on $TRAVIS_OS_NAME" 19 | # npm run build:ssr 20 | # npm run build:prerender 21 | 22 | # run test 23 | echo "npm run test on $TRAVIS_OS_NAME" 24 | npm run test:ci 25 | npm run e2e:ci 26 | -------------------------------------------------------------------------------- /src/app/core/services/auth-guard.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { CanActivate, Router } from '@angular/router'; 3 | import { Observable, of } from 'rxjs'; 4 | 5 | import { AuthService } from './auth.service'; 6 | 7 | @Injectable() 8 | export class AuthGuard implements CanActivate { 9 | constructor(private authService: AuthService, private router: Router) {} 10 | 11 | canActivate(): Observable { 12 | if (this.authService.isLoggedIn()) { 13 | // already logged in so return true 14 | return of(true); 15 | } 16 | 17 | // not logged in so redirect to login page 18 | this.router.navigate(['/']); 19 | return of(false); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/app/app-shell/app-shell.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { AppShellComponent } from './app-shell.component'; 4 | 5 | describe('AppShellComponent', () => { 6 | let component: AppShellComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ AppShellComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(AppShellComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /.codeclimate.yml: -------------------------------------------------------------------------------- 1 | engines: 2 | eslint: 3 | enabled: true 4 | tslint: 5 | enabled: true 6 | config: tslint.json 7 | fixme: 8 | enabled: true 9 | config: 10 | strings: 11 | - FIXME 12 | - TODO 13 | - BUG 14 | csslint: 15 | enabled: true 16 | duplication: 17 | enabled: true 18 | config: 19 | languages: 20 | - javascript 21 | scss-lint: 22 | enabled: true 23 | shellcheck: 24 | enabled: false 25 | ratings: 26 | paths: 27 | - src/** 28 | - "**.css" 29 | - "**.scss" 30 | exclude_paths: 31 | - "docs" 32 | - "documentation" 33 | - "coverage" 34 | - "dist" 35 | - ".scannerwork" 36 | - "**/*.log" 37 | - "**/*.ico" 38 | - "e2e/" 39 | - ".circleci" 40 | - "travisci" 41 | - "src/assets/" 42 | - "src/typings.d.ts" 43 | - "src/app/**/*.spec.ts" 44 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | /.git/ 2 | /.idea/ 3 | 4 | /.circleci/ 5 | /appveyor.yml 6 | /travisci/ 7 | /.travis.yml 8 | 9 | /.dockerignore 10 | 11 | /.github/ 12 | /.scannerwork/ 13 | /coverage/ 14 | /reports/ 15 | /docs/ 16 | **/dist/ 17 | **/node_modules/ 18 | 19 | **/*.spec.ts 20 | **/e2e/ 21 | 22 | **/tslint.json 23 | 24 | **/.env 25 | 26 | **/webpack.*.js 27 | 28 | **/package.json 29 | **/package-lock.json 30 | 31 | **/.angular-cli.json 32 | **/.editorconfig 33 | **/.bootstraprc 34 | **/*.properties 35 | **/*.map 36 | **/*.ejs 37 | **/*.html 38 | **/*.md 39 | **/*.yml 40 | **/*.scss 41 | **/*.css 42 | **/*.jpg 43 | **/*.gif 44 | **/*.jpeg 45 | **/*.png 46 | **/*.ico 47 | **/*.svg 48 | **/*.tgz 49 | **/*.ttf 50 | **/*.txt 51 | **/*.log 52 | 53 | **/.bithoundrc 54 | **/.gitignore 55 | **/.prettierignore 56 | **/.snyk 57 | 58 | **/.DS_Store 59 | **/Thumbs.db 60 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 1.0.0 2 | 3 | ## Features 4 | - first stable release based on Angular 9 with Ivy 5 | 6 | 7 | # Beta 3 (work in progress, but never released) 8 | 9 | ## Features 10 | - upgrade to angular 6 and angular-cli 6 11 | - update all deps also in /servers applying some fixes to be able to compile again node-express-ts 12 | 13 | 14 | # Beta 2 15 | 16 | ## Features 17 | - add JWT login + profile page #18 18 | - add Roboto font from assets #23 19 | - add ngx-toastr #20 20 | - update Font Awesome 5 #23 21 | - add 2 servers (vanilla js + Typescript) 22 | 23 | ## Chores 24 | - general refactoring 25 | - update deps 26 | 27 | 28 | # Beta 1 29 | - first implementation 30 | 31 | Please take a look at `https://github.com/Ks89/angular-cli-skeleton/issues` to see the scheduling for upcoming releases 32 | 33 | If you have a question, please open an issue. 34 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/utils/jwt.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const { JWT_SECRET, SESSION_TIMEOUT_MS } = require('../config'); 4 | const jwt = require('jsonwebtoken'); 5 | const _ = require('lodash'); 6 | 7 | function generateJWTforUser(user = {}) { 8 | return jwt.sign(getJwtToSign(user), JWT_SECRET); // add also ..._SECRET, {expiresIn: '7d'}) without to add exp manually 9 | } 10 | 11 | function getJwtToSign(dataToAdd) { 12 | const expiry = new Date(); 13 | expiry.setTime(expiry.getTime() + parseInt(SESSION_TIMEOUT_MS)); 14 | return { 15 | // ATTENTION!!! 16 | // All these info are public 17 | // don't store private thing here because they 18 | // are visible by users in all browsers (local storage) 19 | id: dataToAdd.id, 20 | exp: parseFloat(expiry.getTime()) 21 | }; 22 | } 23 | 24 | exports.generateJWTforUser = generateJWTforUser; 25 | -------------------------------------------------------------------------------- /src/app/app.server.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { ServerModule } from '@angular/platform-server'; 3 | import { ModuleMapLoaderModule } from '@nguniversal/module-map-ngfactory-loader'; 4 | 5 | import { AppModule } from './app.module'; 6 | import { AppComponent } from './app.component'; 7 | import { RouterModule, Routes } from '@angular/router'; 8 | import { AppShellComponent } from './app-shell/app-shell.component'; 9 | 10 | const routes: Routes = [{ path: 'shell', component: AppShellComponent }]; 11 | 12 | @NgModule({ 13 | imports: [ 14 | // The AppServerModule should import your AppModule followed 15 | // by the ServerModule from @angular/platform-server. 16 | AppModule, 17 | ServerModule, 18 | ModuleMapLoaderModule, // <-- *Important* to have lazy-loaded routes work 19 | RouterModule.forRoot(routes) 20 | ], 21 | bootstrap: [AppComponent], 22 | declarations: [AppShellComponent] 23 | }) 24 | export class AppServerModule {} 25 | -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 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 { 6 | SpecReporter 7 | } = require('jasmine-spec-reporter'); 8 | 9 | /** 10 | * @type { import("protractor").Config } 11 | */ 12 | exports.config = { 13 | allScriptsTimeout: 11000, 14 | specs: [ 15 | './src/**/*.e2e-spec.ts' 16 | ], 17 | capabilities: { 18 | 'browserName': 'chrome' 19 | }, 20 | directConnect: true, 21 | baseUrl: 'http://localhost:4200/', 22 | framework: 'jasmine', 23 | jasmineNodeOpts: { 24 | showColors: true, 25 | defaultTimeoutInterval: 30000, 26 | print: function() {} 27 | }, 28 | onPrepare() { 29 | require('ts-node').register({ 30 | project: require('path').join(__dirname, './tsconfig.json') 31 | }); 32 | jasmine.getEnv().addReporter(new SpecReporter({ 33 | spec: { 34 | displayStacktrace: true 35 | } 36 | })); 37 | } 38 | }; 39 | -------------------------------------------------------------------------------- /src/app/pages/home/home.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

Welcome

4 | 5 |
6 |
7 |

Login with username=admin and password=password

8 |

To be able to login, you must run a server with 'npm start' in /servers folder of this project!!!

9 |
10 |
11 | 12 | 13 |
14 |
15 | 16 | 17 |
18 | 19 |
20 |
21 |
22 | 23 |
24 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Create image based on the official latest Node image from dockerhub 2 | FROM node:latest as builder 3 | 4 | COPY package.json package-lock.json ./ 5 | 6 | # RUN npm set progress=false && npm config set depth 0 && npm cache clean --force 7 | 8 | ## Storing node modules on a separate layer will prevent unnecessary npm installs at each build 9 | RUN npm i && mkdir /ng-app && cp -R ./node_modules ./ng-app 10 | 11 | ## Move to /ng-app (eq: cd /ng-app) 12 | WORKDIR /ng-app 13 | 14 | # Copy everything from host to /ng-app in the container 15 | COPY . . 16 | 17 | ## Build the angular app in production mode and store the artifacts in dist folder 18 | RUN npm run build:prod 19 | 20 | 21 | ### STAGE 2: Setup ### 22 | 23 | FROM nginx 24 | 25 | ## Copy our default nginx config 26 | #COPY nginx/default.conf /etc/nginx/conf.d/ 27 | 28 | ## Remove default nginx website 29 | RUN rm -rf /usr/share/nginx/html/* 30 | 31 | ## From 'builder' stage copy over the artifacts in dist folder to default nginx public folder 32 | COPY --from=builder /ng-app/dist/browser /usr/share/nginx/html 33 | 34 | #CMD ["nginx", "-g", "daemon off;"] 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2019 Stefano Cappa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/app/app.component.scss: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2018 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/app/pages/home/home.scss: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2018 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/app/pages/sw/sw.scss: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2018 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | -------------------------------------------------------------------------------- /travisci/before_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Before install - OS is $TRAVIS_OS_NAME" 4 | 5 | # switch to npm 5 6 | npm install -g npm@6.9.0 7 | npm cache verify 8 | npm prune 9 | npm update 10 | 11 | echo "Exporting env variables dependencies" 12 | # export env variables, thanks to https://github.com/travis-ci/travis-ci/issues/7099 13 | if [[ $TRAVIS_OS_NAME = 'osx' ]]; then 14 | echo "Exporting env variables - OS is $TRAVIS_OS_NAME" 15 | export NODE_ENV=test CI=yes; 16 | echo "NODE_ENV = $NODE_ENV" 17 | echo "CI = $CI" 18 | echo "Exporting env variables - done" 19 | else 20 | echo "Exporting env variables - OS is $TRAVIS_OS_NAME" 21 | export CXX=g++-4.8 NODE_ENV=test CI=yes 22 | echo "CXX = $CXX" 23 | echo "NODE_ENV = $NODE_ENV" 24 | echo "CI = $CI" 25 | echo "Exporting env variables - done" 26 | fi 27 | 28 | echo "Installing global dependencies" 29 | # install global dependencies 30 | if [[ $TRAVIS_OS_NAME = 'osx' ]]; then 31 | echo "Installing $TRAVIS_OS_NAME global dependencies" 32 | sudo npm install -g codeclimate-test-reporter 33 | else 34 | echo "Installing $TRAVIS_OS_NAME global dependencies" 35 | # to fix a problem with nodejs 6 on linux 36 | npm install -g codeclimate-test-reporter 37 | fi 38 | -------------------------------------------------------------------------------- /src/app/pages/lazy/lazy.scss: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2018 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | small { 24 | color: red; 25 | } 26 | -------------------------------------------------------------------------------- /src/manifest.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "client", 3 | "short_name": "client", 4 | "theme_color": "#1976d2", 5 | "background_color": "#fafafa", 6 | "display": "standalone", 7 | "scope": "./", 8 | "start_url": "./", 9 | "icons": [ 10 | { 11 | "src": "assets/icons/icon-72x72.png", 12 | "sizes": "72x72", 13 | "type": "image/png" 14 | }, 15 | { 16 | "src": "assets/icons/icon-96x96.png", 17 | "sizes": "96x96", 18 | "type": "image/png" 19 | }, 20 | { 21 | "src": "assets/icons/icon-128x128.png", 22 | "sizes": "128x128", 23 | "type": "image/png" 24 | }, 25 | { 26 | "src": "assets/icons/icon-144x144.png", 27 | "sizes": "144x144", 28 | "type": "image/png" 29 | }, 30 | { 31 | "src": "assets/icons/icon-152x152.png", 32 | "sizes": "152x152", 33 | "type": "image/png" 34 | }, 35 | { 36 | "src": "assets/icons/icon-192x192.png", 37 | "sizes": "192x192", 38 | "type": "image/png" 39 | }, 40 | { 41 | "src": "assets/icons/icon-384x384.png", 42 | "sizes": "384x384", 43 | "type": "image/png" 44 | }, 45 | { 46 | "src": "assets/icons/icon-512x512.png", 47 | "sizes": "512x512", 48 | "type": "image/png" 49 | } 50 | ] 51 | } 52 | -------------------------------------------------------------------------------- /servers/node-koa-js/.env: -------------------------------------------------------------------------------- 1 | # *************************************************************************** 2 | # * MAIN (app.js) * 3 | # *************************************************************************** 4 | 5 | FRONT_END_PATH=public 6 | LOG_FOLDER=logs 7 | 8 | LARGE_PAYLOAD_MESSAGE=stop it! 9 | EXPRESS_SESSION_SECRET=keyboard cat 10 | COOKIE_SECRET=dshgdadgjasd 11 | 12 | HELMET_HIDE_POWERED_BY=f__k u idiot 13 | HELMET_REFERRER_POLICY=same-origin 14 | HELMET_HPKP_SHA256S_1=AbCdEf123= 15 | HELMET_HPKP_SHA256S_2=ZyXwVu456= 16 | HELMET_HPKP_REPORT_URI=https://example.com/hpkp-report 17 | HELMET_EXPECT_CT_REPORT_URI=https://example.com/expect-ct-report 18 | 19 | # 60 minutes (60*60*1000) = 3600000 20 | RATELIMITER_WINDOW_MS=3600000 21 | RATELIMITER_MAX=1000 22 | RATELIMITER_DELAY_AFTER=800 23 | RATELIMITER_DELAY_MS=3000 24 | RATELIMITER_MESSAGE=Too many requests from this IP, please try again after 60 minutes 25 | 26 | # *************************************************************************** 27 | # * COMMON (variables used everywhere) * 28 | # *************************************************************************** 29 | 30 | JWT_SECRET=db75467dhiuye09476gbznbczo982eyhyfoewhf3g8f764f8yhnjvkdsoifhgwetg7idehuw 31 | SESSION_TIMEOUT_MS=3600000 32 | -------------------------------------------------------------------------------- /ngsw-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/service-worker/config/schema.json", 3 | "index": "/index.html", 4 | "assetGroups": [ 5 | { 6 | "name": "app", 7 | "installMode": "prefetch", 8 | "resources": { 9 | "files": ["/favicon.png", "/index.html", "/manifest.webmanifest", "/404.html", "/500.html", "/*.css", "/*.js"] 10 | } 11 | }, 12 | { 13 | "name": "assets", 14 | "installMode": "lazy", 15 | "updateMode": "prefetch", 16 | "resources": { 17 | "files": ["/assets/**", "/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"] 18 | } 19 | }, 20 | { 21 | "name": "externals", 22 | "installMode": "prefetch", 23 | "updateMode": "prefetch", 24 | "resources": { 25 | "urls": [ 26 | "https://ajax.googleapis.com/**", 27 | "https://fonts.googleapis.com/**", 28 | "https://fonts.gstatic.com/**", 29 | "https://stackpatch.bootstrapcdn.com/**" 30 | ] 31 | } 32 | } 33 | ], 34 | "dataGroups": [ 35 | { 36 | "name": "github-api", 37 | "urls": ["api.github.com/**"], 38 | "cacheConfig": { 39 | "strategy": "freshness", 40 | "maxSize": 15, 41 | "maxAge": "1h", 42 | "timeout": "5s" 43 | } 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /servers/node-express-js/.env: -------------------------------------------------------------------------------- 1 | # *************************************************************************** 2 | # * MAIN (app.js) * 3 | # *************************************************************************** 4 | 5 | FRONT_END_PATH=public 6 | LOG_FOLDER=logs 7 | 8 | LARGE_PAYLOAD_MESSAGE=stop it! 9 | EXPRESS_SESSION_SECRET=keyboard cat 10 | COOKIE_SECRET=dshgdadgjasd 11 | 12 | HELMET_HIDE_POWERED_BY=f__k u idiot 13 | HELMET_REFERRER_POLICY=same-origin 14 | HELMET_HPKP_SHA256S_1=AbCdEf123= 15 | HELMET_HPKP_SHA256S_2=ZyXwVu456= 16 | HELMET_HPKP_REPORT_URI=https://example.com/hpkp-report 17 | HELMET_EXPECT_CT_REPORT_URI=https://example.com/expect-ct-report 18 | 19 | # 60 minutes (60*60*1000) = 3600000 20 | RATELIMITER_WINDOW_MS=3600000 21 | RATELIMITER_MAX=1000 22 | RATELIMITER_DELAY_AFTER=800 23 | RATELIMITER_DELAY_MS=3000 24 | RATELIMITER_MESSAGE=Too many requests from this IP, please try again after 60 minutes 25 | 26 | # *************************************************************************** 27 | # * COMMON (variables used everywhere) * 28 | # *************************************************************************** 29 | 30 | JWT_SECRET=db75467dhiuye09476gbznbczo982eyhyfoewhf3g8f764f8yhnjvkdsoifhgwetg7idehuw 31 | SESSION_TIMEOUT_MS=3600000 32 | -------------------------------------------------------------------------------- /servers/node-express-ts/.env: -------------------------------------------------------------------------------- 1 | # *************************************************************************** 2 | # * MAIN (app.js) * 3 | # *************************************************************************** 4 | 5 | FRONT_END_PATH=public 6 | LOG_FOLDER=logs 7 | 8 | LARGE_PAYLOAD_MESSAGE=stop it! 9 | EXPRESS_SESSION_SECRET=keyboard cat 10 | COOKIE_SECRET=dshgdadgjasd 11 | 12 | HELMET_HIDE_POWERED_BY=f__k u idiot 13 | HELMET_REFERRER_POLICY=same-origin 14 | HELMET_HPKP_SHA256S_1=AbCdEf123= 15 | HELMET_HPKP_SHA256S_2=ZyXwVu456= 16 | HELMET_HPKP_REPORT_URI=https://example.com/hpkp-report 17 | HELMET_EXPECT_CT_REPORT_URI=https://example.com/expect-ct-report 18 | 19 | # 60 minutes (60*60*1000) = 3600000 20 | RATELIMITER_WINDOW_MS=3600000 21 | RATELIMITER_MAX=1000 22 | RATELIMITER_DELAY_AFTER=800 23 | RATELIMITER_DELAY_MS=3000 24 | RATELIMITER_MESSAGE=Too many requests from this IP, please try again after 60 minutes 25 | 26 | # *************************************************************************** 27 | # * COMMON (variables used everywhere) * 28 | # *************************************************************************** 29 | 30 | JWT_SECRET=db75467dhiuye09476gbznbczo982eyhyfoewhf3g8f764f8yhnjvkdsoifhgwetg7idehuw 31 | SESSION_TIMEOUT_MS=3600000 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | /node-express-server/node_modules/ 38 | jspm_packages/ 39 | 40 | # Typescript v1 declaration files 41 | typings/ 42 | 43 | # Optional npm cache directory 44 | .npm 45 | 46 | # Optional eslint cache 47 | .eslintcache 48 | 49 | # Optional REPL history 50 | .node_repl_history 51 | 52 | # Output of 'npm pack' 53 | *.tgz 54 | 55 | # Yarn Integrity file 56 | .yarn-integrity 57 | 58 | # mac os files 59 | .DS_Store 60 | 61 | # IntelliJ folder 62 | .idea 63 | 64 | # Angular build and temp directories 65 | **/dist 66 | **/docs 67 | 68 | # Angulardoc file 69 | .angulardoc.json 70 | 71 | **/public/* 72 | -------------------------------------------------------------------------------- /servers/node-koa-js/.env_prod: -------------------------------------------------------------------------------- 1 | # *************************************************************************** 2 | # * MAIN (app.js) * 3 | # *************************************************************************** 4 | 5 | FRONT_END_PATH=public 6 | LOG_FOLDER=logs 7 | 8 | LARGE_PAYLOAD_MESSAGE=stop it! 9 | EXPRESS_SESSION_SECRET=super secret prod password 10 | COOKIE_SECRET=secretcookiepwd 11 | 12 | HELMET_HIDE_POWERED_BY=php 4.1.0 13 | HELMET_REFERRER_POLICY=same-origin 14 | HELMET_HPKP_SHA256S_1=AbCdEf123= 15 | HELMET_HPKP_SHA256S_2=ZyXwVu456= 16 | HELMET_HPKP_REPORT_URI=https://example.com/hpkp-report 17 | HELMET_EXPECT_CT_REPORT_URI=https://example.com/expect-ct-report 18 | 19 | # 60 minutes (60*60*1000) = 3600000 20 | RATELIMITER_WINDOW_MS=3600000 21 | RATELIMITER_MAX=1000 22 | RATELIMITER_DELAY_AFTER=800 23 | RATELIMITER_DELAY_MS=3000 24 | RATELIMITER_MESSAGE=Too many requests from this IP, please try again after 60 minutes 25 | 26 | # *************************************************************************** 27 | # * COMMON (variables used everywhere) * 28 | # *************************************************************************** 29 | 30 | JWT_SECRET=dajsdhye09476gbznbczo982eyhyfoewhf3g8f764f8yhnjvkdsoifhgwetg7idehuw 31 | SESSION_TIMEOUT_MS=3600000 32 | -------------------------------------------------------------------------------- /servers/node-express-js/.env_prod: -------------------------------------------------------------------------------- 1 | # *************************************************************************** 2 | # * MAIN (app.js) * 3 | # *************************************************************************** 4 | 5 | FRONT_END_PATH=public 6 | LOG_FOLDER=logs 7 | 8 | LARGE_PAYLOAD_MESSAGE=stop it! 9 | EXPRESS_SESSION_SECRET=super secret prod password 10 | COOKIE_SECRET=secretcookiepwd 11 | 12 | HELMET_HIDE_POWERED_BY=php 4.1.0 13 | HELMET_REFERRER_POLICY=same-origin 14 | HELMET_HPKP_SHA256S_1=AbCdEf123= 15 | HELMET_HPKP_SHA256S_2=ZyXwVu456= 16 | HELMET_HPKP_REPORT_URI=https://example.com/hpkp-report 17 | HELMET_EXPECT_CT_REPORT_URI=https://example.com/expect-ct-report 18 | 19 | # 60 minutes (60*60*1000) = 3600000 20 | RATELIMITER_WINDOW_MS=3600000 21 | RATELIMITER_MAX=1000 22 | RATELIMITER_DELAY_AFTER=800 23 | RATELIMITER_DELAY_MS=3000 24 | RATELIMITER_MESSAGE=Too many requests from this IP, please try again after 60 minutes 25 | 26 | # *************************************************************************** 27 | # * COMMON (variables used everywhere) * 28 | # *************************************************************************** 29 | 30 | JWT_SECRET=dajsdhye09476gbznbczo982eyhyfoewhf3g8f764f8yhnjvkdsoifhgwetg7idehuw 31 | SESSION_TIMEOUT_MS=3600000 32 | -------------------------------------------------------------------------------- /servers/node-express-ts/.env_prod: -------------------------------------------------------------------------------- 1 | # *************************************************************************** 2 | # * MAIN (app.js) * 3 | # *************************************************************************** 4 | 5 | FRONT_END_PATH=public 6 | LOG_FOLDER=logs 7 | 8 | LARGE_PAYLOAD_MESSAGE=stop it! 9 | EXPRESS_SESSION_SECRET=super secret prod password 10 | COOKIE_SECRET=secretcookiepwd 11 | 12 | HELMET_HIDE_POWERED_BY=php 4.1.0 13 | HELMET_REFERRER_POLICY=same-origin 14 | HELMET_HPKP_SHA256S_1=AbCdEf123= 15 | HELMET_HPKP_SHA256S_2=ZyXwVu456= 16 | HELMET_HPKP_REPORT_URI=https://example.com/hpkp-report 17 | HELMET_EXPECT_CT_REPORT_URI=https://example.com/expect-ct-report 18 | 19 | # 60 minutes (60*60*1000) = 3600000 20 | RATELIMITER_WINDOW_MS=3600000 21 | RATELIMITER_MAX=1000 22 | RATELIMITER_DELAY_AFTER=800 23 | RATELIMITER_DELAY_MS=3000 24 | RATELIMITER_MESSAGE=Too many requests from this IP, please try again after 60 minutes 25 | 26 | # *************************************************************************** 27 | # * COMMON (variables used everywhere) * 28 | # *************************************************************************** 29 | 30 | JWT_SECRET=dajsdhye09476gbznbczo982eyhyfoewhf3g8f764f8yhnjvkdsoifhgwetg7idehuw 31 | SESSION_TIMEOUT_MS=3600000 32 | -------------------------------------------------------------------------------- /src/app/pages/profile/profile.scss: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2018 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | 24 | .gif { 25 | width: 200px; 26 | height: 200px; 27 | background: url("/assets/giphy.gif") no-repeat; 28 | } 29 | -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | export const environment = { 26 | production: true, 27 | showDevModule: false, 28 | hmr: false 29 | }; 30 | -------------------------------------------------------------------------------- /travisci/before_script.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | echo "Before script - OS is $TRAVIS_OS_NAME" 4 | 5 | echo "Apply this temporary fix https://github.com/travis-ci/travis-ci/issues/9024" 6 | sudo chown root /opt/google/chrome/chrome-sandbox 7 | sudo chmod 4755 /opt/google/chrome/chrome-sandbox 8 | 9 | # update webdriver (like npm run webdriver:update) 10 | node ./node_modules/protractor/bin/webdriver-manager update 11 | # rebuild again node-sass 12 | npm rebuild node-sass 13 | 14 | echo "Setting xvfb based on TRAVIS_OS_NAME" 15 | # setting xvfb on Linux https://docs.travis-ci.com/user/gui-and-headless-browsers/#Using-xvfb-to-Run-Tests-That-Require-a-GUI 16 | if [[ $TRAVIS_OS_NAME == 'linux' ]]; then 17 | # config required to run browsers 18 | export DISPLAY=:99.0 19 | echo "DISPLAY is $DISPLAY" 20 | sh -e /etc/init.d/xvfb start 21 | sleep 3 # give xvfb some time to start 22 | else 23 | echo "Installing cask on $TRAVIS_OS_NAME" 24 | brew tap caskroom/cask 25 | 26 | echo "Installing chrome on $TRAVIS_OS_NAME" 27 | brew cask install google-chrome 28 | fi 29 | 30 | 31 | # codeclimate test reporter 32 | echo "Preparing codeclimate test reporter - OS is $TRAVIS_OS_NAME" 33 | curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter 34 | chmod +x ./cc-test-reporter 35 | ./cc-test-reporter before-build 36 | -------------------------------------------------------------------------------- /src/app/pages/lazy/lazy.routes.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { LazyComponent } from './lazy.component'; 26 | 27 | /** 28 | * Array of lazy loaded module's routes for the app SPA 29 | */ 30 | export const routes = [{ path: '', component: LazyComponent }]; 31 | -------------------------------------------------------------------------------- /servers/node-express-js/src/routes/apis.js: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2019 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | 'use strict'; 24 | 25 | module.exports = { 26 | BASE_API_PATH: '/api', 27 | 28 | GET_KEEP_ALIVE: '/keepAlive', 29 | POST_LOGIN: '/login', 30 | GET_SECRET: '/secret', 31 | 32 | GET_LOGOUT: '/logout' 33 | }; 34 | -------------------------------------------------------------------------------- /servers/node-express-js/src/routes/controllers/keepalive.js: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2019 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | 'use strict'; 24 | 25 | const logger = require('../../logger'); 26 | 27 | module.exports.keepAlive = (req, res) => { 28 | logger.debug('REST keepAlive'); 29 | 30 | res.json({ message: 'Express is up!' }); 31 | }; 32 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/routes/controllers/auth.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const _ = require('lodash'); 4 | 5 | const { UnauthorizedError } = require('../../utils/errors'); 6 | const { generateJWTforUser } = require('../../utils/jwt'); 7 | const db = require('../../db'); 8 | 9 | module.exports = { 10 | async login(ctx) { 11 | const { body } = ctx.request; 12 | 13 | console.log('body', body); 14 | 15 | if (!_.isObject(body) || !body.username || !body.password) { 16 | console.error('Username or password not valid'); 17 | ctx.throw(401, new UnauthorizedError()); 18 | } 19 | 20 | const username = body.username; 21 | const password = body.password; 22 | 23 | // usually this would be a database call: 24 | let user = db.db[_.findIndex(db.db, o => o && o.credential && o.credential.username === username && o.credential.password === password)]; 25 | 26 | if (!user || !user.credential) { 27 | console.error('User not found'); 28 | ctx.throw(401, new UnauthorizedError()); 29 | } 30 | 31 | if (user.credential.password !== password) { 32 | console.error('Wrong password'); 33 | ctx.throw(401, new UnauthorizedError()); 34 | } 35 | 36 | const token = generateJWTforUser(user.credential); 37 | 38 | console.log('token', token); 39 | 40 | ctx.body = { token: token }; 41 | }, 42 | 43 | async logout(ctx) { 44 | ctx.state.jwt = undefined; 45 | ctx.body = { message: 'Logout successfull' }; 46 | } 47 | }; 48 | -------------------------------------------------------------------------------- /servers/node-express-js/src/routes/controllers/secret.js: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2019 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | 'use strict'; 24 | 25 | const logger = require('../../logger'); 26 | 27 | module.exports.secret = (req, res) => { 28 | logger.debug('REST secret'); 29 | res.json({ message: 'This is a secret message from an authenticated rest API' }); 30 | }; 31 | -------------------------------------------------------------------------------- /servers/node-express-ts/src/routes/apis.ts: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2019 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | export const BASE_API_PATH: string = '/api'; 24 | 25 | export const GET_KEEP_ALIVE: string = '/keepAlive'; 26 | export const POST_LOGIN: string = '/login'; 27 | export const GET_SECRET: string = '/secret'; 28 | 29 | export const GET_LOGOUT: string = '/logout'; 30 | -------------------------------------------------------------------------------- /servers/node-express-ts/src/routes/controllers/keepalive.ts: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2019 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | import { Request, Response } from 'express'; 24 | 25 | import { logger } from '../../logger'; 26 | 27 | export function keepAlive(req: Request, res: Response) { 28 | logger.debug('REST keepAlive'); 29 | 30 | res.json({ message: 'Express is up!' }); 31 | } 32 | -------------------------------------------------------------------------------- /src/app/shared/components/navbar/navbar.html: -------------------------------------------------------------------------------- 1 | 30 |
31 |
32 | -------------------------------------------------------------------------------- /servers/node-express-ts/src/routes/controllers/secret.ts: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2019 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | import { Request, Response } from 'express'; 24 | 25 | import { logger } from '../../logger'; 26 | 27 | export function secret(req: Request, res: Response) { 28 | logger.debug('REST secret'); 29 | res.json({ message: 'This is a secret message from an authenticated rest API' }); 30 | } 31 | -------------------------------------------------------------------------------- /servers/node-koa-js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-cli-skeleton-server", 3 | "version": "1.0.0", 4 | "author": "Stefano Cappa", 5 | "description": "Angular skeleton with angular-cli - server side in koajs + Javascript", 6 | "license": "MIT", 7 | "homepage": "https://github.com/Ks89", 8 | "private": true, 9 | "repository": "https://github.com/Ks89/angular-cli-skeleton", 10 | "main": "src/bin/www", 11 | "engines": { 12 | "node": ">=12.0.0", 13 | "npm": ">=6.9.0" 14 | }, 15 | "scripts": { 16 | "start": "npm run start:dev", 17 | "start:dev": "nodemon src/bin/www", 18 | "start:debug": "cross-env DEBUG=* node src/bin/www", 19 | "start:prod": "pm2 start pm2.json --env production", 20 | "stop:prod": "pm2 stop src/bin/www", 21 | "jshint": "jshint ." 22 | }, 23 | "dependencies": { 24 | "body-parser": "^1.19.0", 25 | "cookie-parser": "^1.4.4", 26 | "csurf": "^1.10.0", 27 | "dotenv": "^8.2.0", 28 | "http-shutdown": "^1.2.1", 29 | "koa": "^2.11.0", 30 | "koa-bodyparser": "^4.2.1", 31 | "koa-helmet": "^5.2.0", 32 | "koa-jwt": "^3.6.0", 33 | "koa-logger": "^3.2.1", 34 | "koa-response-time": "^2.1.0", 35 | "koa-router": "^8.0.8", 36 | "koa-static": "^5.0.0", 37 | "lodash": "^4.17.15", 38 | "request": "^2.88.0", 39 | "request-promise": "^4.2.5" 40 | }, 41 | "devDependencies": { 42 | "cpr": "^3.0.1", 43 | "cross-env": "^7.0.2", 44 | "jshint": "^2.10.3", 45 | "nodemon": "^2.0.2", 46 | "pm2": "^4.1.2", 47 | "rimraf": "^3.0.0" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/app/shared/components/footer/footer.component.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { Component } from '@angular/core'; 26 | 27 | /** 28 | * Footer of your application with copyright info and so on 29 | */ 30 | @Component({ 31 | selector: 'app-footer', 32 | styleUrls: ['footer.scss'], 33 | templateUrl: 'footer.html' 34 | }) 35 | export class FooterComponent {} 36 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/app.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const config = require('./config'); 4 | const http = require('http'); 5 | const Koa = require('koa'); 6 | 7 | const app = new Koa(); 8 | 9 | const koaStatic = require('koa-static'); 10 | const responseTime = require('koa-response-time'); 11 | const helmet = require('koa-helmet'); 12 | const logger = require('koa-logger'); 13 | const bodyParser = require('koa-bodyparser'); 14 | const httpShutdown = require('http-shutdown'); 15 | 16 | const jwt = require('./middlewares/jwt'); 17 | // const error = require('middleware/error-middleware'); 18 | 19 | const routes = require('./routes'); 20 | 21 | if (!config.isTest()) { 22 | app.use(responseTime()); 23 | app.use(helmet()); 24 | } 25 | 26 | app.use(logger()); 27 | 28 | app.use(jwt); 29 | 30 | app.use(bodyParser({ enableTypes: ['json'] })); 31 | 32 | app.use(routes.routes()); 33 | app.use(routes.allowedMethods()); 34 | 35 | app.use(koaStatic(config.FRONT_END_PATH)); 36 | 37 | app.server = httpShutdown(http.createServer(app.callback())); 38 | 39 | app.shutDown = function shutDown() { 40 | let err; 41 | 42 | console.log('Shutdown'); 43 | 44 | if (this.server.listening) { 45 | this.server.shutdown(error => { 46 | if (error) { 47 | console.error(error); 48 | err = error; 49 | } 50 | 51 | this.db 52 | .destroy() 53 | .catch(error => { 54 | console.error(error); 55 | err = error; 56 | }) 57 | .then(() => process.exit(err ? 1 : 0)); 58 | }); 59 | } 60 | }; 61 | 62 | module.exports = app; 63 | -------------------------------------------------------------------------------- /src/app/pages/404/not-found.component.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { Component } from '@angular/core'; 26 | 27 | /** 28 | * Module used to display an error page when you are navigating to a wrong route 29 | * (or not defined into `app.routing.ts`) 30 | */ 31 | @Component({ 32 | selector: 'app-not-found', 33 | template: '

Error 404: Not found

' 34 | }) 35 | export class NotFoundComponent {} 36 | -------------------------------------------------------------------------------- /servers/node-express-js/src/passport.js: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2019 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | 'use strict'; 24 | 25 | const config = require('./config'); 26 | 27 | let jwtOpts; 28 | 29 | module.exports.buildJwtOptions = jwtFromRequest => { 30 | jwtOpts = {}; 31 | jwtOpts.jwtFromRequest = jwtFromRequest; 32 | jwtOpts.secretOrKey = config.JWT_SECRET; 33 | return jwtOpts; 34 | }; 35 | 36 | module.exports.getJwtOptions = () => { 37 | return jwtOpts; 38 | }; 39 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | angular-cli-skeleton 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/theme/_theme.scss: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | // search all occurrences in all code, also html, because it's everywhere 26 | $color-primary: #101010; 27 | $color-secondary: #9e9e9e; 28 | $color-white: #FFF; 29 | $color-black: #000; 30 | $color-light-black: #343A40; 31 | $color-code: #c100e0; 32 | $color-url: #0060b7; 33 | 34 | //$font-huge: 24px; 35 | $font-big: 18px; 36 | $font-middle: 14px; 37 | $font-small: 12px; 38 | $font-very-small: 10px; 39 | -------------------------------------------------------------------------------- /src/app/core/actions/hello-example.actions.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /* tslint:disable:max-classes-per-file */ 26 | 27 | // This file is used into ../../reducers/index.ts 28 | 29 | import { createAction, props } from '@ngrx/store'; 30 | 31 | export const SAY_HELLO = '[Example] Say Hello'; 32 | export const SAY_BYEBYE = '[Example] Say ByeBye'; 33 | 34 | export const sayHello = createAction(SAY_HELLO); 35 | export const sayByeBye = createAction(SAY_BYEBYE); 36 | -------------------------------------------------------------------------------- /src/app/pages/components.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { HomeComponent } from './home/home.component'; 26 | import { NotFoundComponent } from './404/not-found.component'; 27 | import { ServiceWorkerComponent } from './sw/sw.component'; 28 | import { ProfileComponent } from './profile/profile.component'; 29 | 30 | /** 31 | * Array of exported components 32 | */ 33 | export const COMPONENTS = [HomeComponent, ProfileComponent, NotFoundComponent, ServiceWorkerComponent]; 34 | -------------------------------------------------------------------------------- /src/app/pages/lazy/actions/page-num.actions.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /* tslint:disable:max-classes-per-file */ 26 | 27 | // This file is used into ../../reducers/index.ts 28 | 29 | import { createAction, props } from '@ngrx/store'; 30 | 31 | export const GET_PAGE = '[PageNum] Get Page'; 32 | export const SET_PAGE = '[PageNum] Set Page'; 33 | 34 | export const getPageNum = createAction(GET_PAGE); 35 | export const setPageNum = createAction(SET_PAGE, props<{ payload }>()); 36 | -------------------------------------------------------------------------------- /servers/node-express-js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-cli-skeleton-server", 3 | "version": "1.0.0", 4 | "author": "Stefano Cappa", 5 | "description": "Angular skeleton with angular-cli - server side in Javascript", 6 | "license": "MIT", 7 | "homepage": "https://github.com/Ks89", 8 | "private": true, 9 | "repository": "https://github.com/Ks89/angular-cli-skeleton", 10 | "main": "bin/www", 11 | "engines": { 12 | "node": ">=12.0.0", 13 | "npm": ">=6.9.0" 14 | }, 15 | "scripts": { 16 | "start": "npm run start:dev", 17 | "start:dev": "nodemon bin/www", 18 | "start:debug": "cross-env DEBUG=* node bin/www", 19 | "start:prod": "pm2 start pm2.json --env production", 20 | "stop:prod": "pm2 stop bin/www", 21 | "jshint": "jshint ." 22 | }, 23 | "dependencies": { 24 | "body-parser": "^1.18.3", 25 | "compression": "^1.7.2", 26 | "cookie-parser": "^1.4.5", 27 | "csurf": "^1.11.0", 28 | "dotenv": "^8.2.0", 29 | "expect-ct": "^0.3.0", 30 | "express": "^4.16.3", 31 | "express-content-length-validator": "^1.0.0", 32 | "express-rate-limit": "^5.1.1", 33 | "express-session": "^1.15.6", 34 | "express-slow-down": "^1.3.1", 35 | "helmet": "^3.21.3", 36 | "hpp": "^0.2.3", 37 | "jsonwebtoken": "^8.2.1", 38 | "lodash": "^4.17.10", 39 | "passport": "^0.4.1", 40 | "passport-jwt": "^4.0.0", 41 | "winston": "^3.2.1", 42 | "winston-daily-rotate-file": "^4.4.2" 43 | }, 44 | "devDependencies": { 45 | "cpr": "^3.0.1", 46 | "cross-env": "^7.0.2", 47 | "jshint": "^2.11.0", 48 | "nodemon": "^2.0.2", 49 | "pm2": "^4.2.3", 50 | "rimraf": "^3.0.2" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/app/shared/components/components.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { FooterComponent } from './footer/footer.component'; 26 | import { NavbarComponent } from './navbar/navbar.component'; 27 | import { PageHeaderComponent } from './page-header/page-header.component'; 28 | 29 | export { PageHeader } from './page-header/page-header.component'; 30 | 31 | /** 32 | * Array of exported components 33 | */ 34 | export const SHARED_COMPONENTS = [FooterComponent, NavbarComponent, PageHeaderComponent]; 35 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | // The file contents for the current environment will overwrite these during build. 26 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 27 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 28 | // The list of which env maps to which file can be found in `.angular-cli.json`. 29 | 30 | export const environment = { 31 | production: false, 32 | showDevModule: true, 33 | hmr: false 34 | }; 35 | -------------------------------------------------------------------------------- /src/environments/environment.hmr.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | // The file contents for the current environment will overwrite these during build. 26 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 27 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 28 | // The list of which env maps to which file can be found in `.angular-cli.json`. 29 | 30 | export const environment = { 31 | production: false, 32 | showDevModule: true, 33 | hmr: true 34 | }; 35 | -------------------------------------------------------------------------------- /servers/node-express-ts/src/passport.ts: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2019 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | import * as config from './config'; 24 | import { JwtFromRequestFunction, StrategyOptions } from 'passport-jwt'; 25 | 26 | const jwtOpts: StrategyOptions = {}; 27 | 28 | export function buildJwtOptions(jwtFromRequest: JwtFromRequestFunction): StrategyOptions { 29 | jwtOpts.jwtFromRequest = jwtFromRequest; 30 | jwtOpts.secretOrKey = config.JWT_SECRET; 31 | return jwtOpts; 32 | } 33 | 34 | export function getJwtOptions(): StrategyOptions { 35 | return jwtOpts; 36 | } 37 | -------------------------------------------------------------------------------- /src/app/shared/components/footer/footer.scss: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2018 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | html { 24 | position: relative; 25 | min-height: 100%; 26 | } 27 | 28 | body { 29 | margin-bottom: 60px; 30 | color: #5a5a5a; 31 | 32 | > .container { 33 | padding: 60px 15px 0; 34 | 35 | &.text-muted { 36 | margin: 20px 0; 37 | } 38 | } 39 | } 40 | 41 | .footer { 42 | position: absolute; 43 | bottom: 0; 44 | width: 100%; 45 | height: 60px; 46 | background-color: #f5f5f5; 47 | 48 | > .container { 49 | padding-right: 15px; 50 | padding-left: 15px; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main.server.ts: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | * Load `$localize` onto the global scope - used if i18n tags appear in Angular templates. 3 | */ 4 | import '@angular/localize/init'; 5 | /* 6 | * MIT License 7 | * 8 | * Copyright (c) 2017-2019 Stefano Cappa 9 | * 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy 11 | * of this software and associated documentation files (the "Software"), to deal 12 | * in the Software without restriction, including without limitation the rights 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | * copies of the Software, and to permit persons to whom the Software is 15 | * furnished to do so, subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in all 18 | * copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | * SOFTWARE. 27 | */ 28 | 29 | import { enableProdMode } from '@angular/core'; 30 | import 'zone.js/dist/zone-node'; 31 | 32 | import { environment } from './environments/environment'; 33 | 34 | if (environment.production) { 35 | enableProdMode(); 36 | } 37 | 38 | export { AppServerModule } from './app/app.server.module'; 39 | -------------------------------------------------------------------------------- /servers/node-express-js/src/db.js: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2019 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | 'use strict'; 24 | 25 | const db = require('./db.json'); 26 | 27 | // Don't use a const here! 28 | // this is a private variable. 29 | // To access to 'tokens' use get, set and remove to prevent issues 30 | let tokens = []; 31 | 32 | function getTokens() { 33 | return tokens; 34 | } 35 | 36 | function setTokens(newTokens) { 37 | tokens = newTokens; 38 | } 39 | 40 | function removeTokens() { 41 | tokens = []; 42 | } 43 | 44 | module.exports = { 45 | getTokens: getTokens, 46 | setTokens: setTokens, 47 | removeTokens: removeTokens, 48 | db: db 49 | }; 50 | -------------------------------------------------------------------------------- /src/assets/ring.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /servers/node-express-ts/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "class-name": true, 4 | "comment-format": [ 5 | true, 6 | "check-space" 7 | ], 8 | "indent": [ 9 | true, 10 | "spaces" 11 | ], 12 | "one-line": [ 13 | true, 14 | "check-open-brace", 15 | "check-whitespace" 16 | ], 17 | "no-var-keyword": true, 18 | "quotemark": [ 19 | true, 20 | "single", 21 | "avoid-escape" 22 | ], 23 | "semicolon": [ 24 | true, 25 | "always", 26 | "ignore-bound-class-methods" 27 | ], 28 | "whitespace": [ 29 | true, 30 | "check-branch", 31 | "check-decl", 32 | "check-operator", 33 | "check-module", 34 | "check-separator", 35 | "check-type" 36 | ], 37 | "typedef-whitespace": [ 38 | true, 39 | { 40 | "call-signature": "nospace", 41 | "index-signature": "nospace", 42 | "parameter": "nospace", 43 | "property-declaration": "nospace", 44 | "variable-declaration": "nospace" 45 | }, 46 | { 47 | "call-signature": "onespace", 48 | "index-signature": "onespace", 49 | "parameter": "onespace", 50 | "property-declaration": "onespace", 51 | "variable-declaration": "onespace" 52 | } 53 | ], 54 | "no-internal-module": true, 55 | "no-trailing-whitespace": true, 56 | "no-null-keyword": true, 57 | "prefer-const": true, 58 | "jsdoc-format": true 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/app/core/services/services.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { ExampleService } from './example.service'; 26 | import { GithubService } from './github.service'; 27 | import { AuthService } from './auth.service'; 28 | import { AuthGuard } from './auth-guard.service'; 29 | 30 | export { ExampleService } from './example.service'; 31 | export { GithubService } from './github.service'; 32 | export { AuthService } from './auth.service'; 33 | export { AuthGuard } from './auth-guard.service'; 34 | 35 | /** 36 | * Array of core services 37 | */ 38 | export const CORE_SERVICES: any[] = [ExampleService, GithubService, AuthService, AuthGuard]; 39 | -------------------------------------------------------------------------------- /src/app/core/module-import-guard.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /** 26 | * function used to throw an error if you try to import a module multiple times. This is the recommended way by Google. 27 | * @param parentModule Tha parent module (reference to the module itself, for instance CoreModule) 28 | * @param moduleName String that represents the module name that you want to load (for instance 'CoreModule') 29 | */ 30 | export function throwIfAlreadyLoaded(parentModule: any, moduleName: string) { 31 | if (parentModule) { 32 | throw new Error(`${moduleName} has already been loaded. Import Core modules in the AppModule only.`); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /webpack.server.config.js: -------------------------------------------------------------------------------- 1 | // taken from https://github.com/angular/universal-starter/blob/master/webpack.server.config.js 2 | 3 | // Work around for https://github.com/angular/angular-cli/issues/7200 4 | 5 | const path = require('path'); 6 | const webpack = require('webpack'); 7 | 8 | module.exports = { 9 | mode: 'none', 10 | entry: { 11 | // This is our Express server for Dynamic universal 12 | server: './server.ts', 13 | // This is an example of Static prerendering (generative) 14 | prerender: './prerender.ts' 15 | }, 16 | target: 'node', 17 | resolve: { extensions: ['.ts', '.js'] }, 18 | // Make sure we don't include all node_modules 19 | externals: [/node_modules/], 20 | optimization: { 21 | minimize: false 22 | }, 23 | output: { 24 | // Puts the output at the root of the dist folder 25 | path: path.join(__dirname, 'dist'), 26 | filename: '[name].js' 27 | }, 28 | module: { 29 | rules: [ 30 | { test: /\.ts$/, loader: 'ts-loader' }, 31 | { 32 | // Mark files inside `@angular/core` as using SystemJS style dynamic imports. 33 | // Removing this will cause deprecation warnings to appear. 34 | test: /(\\|\/)@angular(\\|\/)core(\\|\/).+\.js$/, 35 | parser: { system: true }, 36 | }, 37 | ] 38 | }, 39 | plugins: [ 40 | new webpack.ContextReplacementPlugin( 41 | // fixes WARNING Critical dependency: the request of a dependency is an expression 42 | /(.+)?angular(\\|\/)core(.+)?/, 43 | path.join(__dirname, 'src'), // location of your src 44 | {} // a map of your routes 45 | ), 46 | new webpack.ContextReplacementPlugin( 47 | // fixes WARNING Critical dependency: the request of a dependency is an expression 48 | /(.+)?express(\\|\/)(.+)?/, 49 | path.join(__dirname, 'src'), 50 | {} 51 | ) 52 | ] 53 | }; 54 | -------------------------------------------------------------------------------- /src/hmr.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { NgModuleRef, ApplicationRef } from '@angular/core'; 26 | import { createNewHosts } from '@angularclass/hmr'; 27 | 28 | export const hmrBootstrap = (module: any, bootstrap: () => Promise>) => { 29 | let ngModule: NgModuleRef; 30 | module.hot.accept(); 31 | bootstrap().then(mod => (ngModule = mod)); 32 | module.hot.dispose(() => { 33 | const appRef: ApplicationRef = ngModule.injector.get(ApplicationRef); 34 | const elements = appRef.components.map(c => c.location.nativeElement); 35 | const makeVisible = createNewHosts(elements); 36 | ngModule.destroy(); 37 | makeVisible(); 38 | }); 39 | }; 40 | -------------------------------------------------------------------------------- /src/app/shared/shared.module.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { NgModule } from '@angular/core'; 26 | import { CommonModule } from '@angular/common'; 27 | import { RouterModule } from '@angular/router'; 28 | 29 | import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; 30 | 31 | import { SHARED_COMPONENTS } from './components/components'; 32 | 33 | /** 34 | * Shared module that you can import everywhere, because it haven't providers. 35 | * It contains navbar, page-header and so on. 36 | */ 37 | @NgModule({ 38 | imports: [CommonModule, RouterModule, NgbModule], 39 | exports: [SHARED_COMPONENTS], 40 | declarations: [SHARED_COMPONENTS], 41 | providers: [] 42 | }) 43 | export class SharedModule {} 44 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/bin/www: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | 5 | const config = require('../config'); 6 | const app = require('../app'); 7 | const debug = require('debug')('ks89:server'); 8 | 9 | /** 10 | * Get port from environment and store in Express. 11 | */ 12 | let port = normalizePort(config.PORT || '3000'); 13 | console.log(`Port is: ${port}`); 14 | 15 | /** 16 | * Listen on provided port, on all network interfaces. 17 | */ 18 | app.server.listen(port, config.HOST); 19 | app.server.on('error', onError); 20 | app.server.on('listening', onListening); 21 | 22 | /** 23 | * Normalize a port into a number, string, or false. 24 | */ 25 | function normalizePort(val) { 26 | let port = parseInt(val, 10); 27 | 28 | if (isNaN(port)) { 29 | // named pipe 30 | return val; 31 | } 32 | 33 | if (port >= 0) { 34 | // port number 35 | return port; 36 | } 37 | 38 | return false; 39 | } 40 | 41 | /** 42 | * Event listener for HTTP server "error" event. 43 | */ 44 | function onError(error) { 45 | if (error.syscall !== 'listen') { 46 | throw error; 47 | } 48 | 49 | let bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; 50 | 51 | // handle specific listen errors with friendly messages 52 | switch (error.code) { 53 | case 'EACCES': 54 | console.error(bind + ' requires elevated privileges'); 55 | process.exit(1); 56 | break; 57 | case 'EADDRINUSE': 58 | console.error(bind + ' is already in use'); 59 | process.exit(1); 60 | break; 61 | default: 62 | throw error; 63 | } 64 | } 65 | 66 | /** 67 | * Event listener for HTTP server "listening" event. 68 | */ 69 | function onListening() { 70 | let addr = app.server.address(); 71 | let bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; 72 | debug(`Listening on ${bind}`); 73 | console.log(`Listening on ${bind}`); 74 | } 75 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 26 | 27 | import 'zone.js/dist/zone-testing'; 28 | import { getTestBed } from '@angular/core/testing'; 29 | import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; 30 | 31 | declare const require: any; 32 | 33 | // First, initialize the Angular testing environment. 34 | getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); 35 | // Then we find all the tests. 36 | const context = require.context('./', true, /\.spec\.ts$/); 37 | // And load the modules. 38 | context.keys().map(context); 39 | -------------------------------------------------------------------------------- /src/app/shared/components/page-header/page-header.component.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /* tslint:disable:max-classes-per-file */ 26 | 27 | import { Component, Input } from '@angular/core'; 28 | 29 | /** 30 | * Page header class 31 | */ 32 | export class PageHeader { 33 | title: string; 34 | strapline: string; 35 | constructor(title: string, strapline: string) { 36 | this.title = title; 37 | this.strapline = strapline; 38 | } 39 | } 40 | 41 | /** 42 | * Page header component to display a big title and a smaller strapline (or subtitle) 43 | */ 44 | @Component({ 45 | selector: 'app-page-header', 46 | templateUrl: 'page-header.html' 47 | }) 48 | export class PageHeaderComponent { 49 | @Input() 50 | header: PageHeader; 51 | } 52 | -------------------------------------------------------------------------------- /src/app/pages/lazy/reducers/page-num.reducers.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | // This file is used into ../../reducers/index.ts 26 | 27 | import { Action, createReducer, on } from '@ngrx/store'; 28 | 29 | import * as PageNumActions from '../actions/page-num.actions'; 30 | 31 | export const pageNumKey = 'pageNum'; 32 | 33 | export interface State { 34 | pageNum: number; 35 | } 36 | 37 | const initialState: State = { 38 | pageNum: 0 39 | }; 40 | 41 | const pageNumReducer = createReducer( 42 | initialState, 43 | on(PageNumActions.getPageNum, state => state), 44 | on(PageNumActions.setPageNum, (state, { payload }) => ({ 45 | pageNum: payload 46 | })) 47 | ); 48 | 49 | // required to support AOT 50 | export function reducer(state: State | undefined, action: Action) { 51 | return pageNumReducer(state, action); 52 | } 53 | -------------------------------------------------------------------------------- /src/app/core/services/example.service.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { Injectable } from '@angular/core'; 26 | import { HttpClient } from '@angular/common/http'; 27 | 28 | import { Observable } from 'rxjs'; 29 | 30 | import { AuthService } from './auth.service'; 31 | 32 | export interface MessageResponse { 33 | message: string; 34 | } 35 | 36 | /** 37 | * Example of a protected Angular Service 38 | */ 39 | @Injectable() 40 | export class ExampleService { 41 | constructor(private http: HttpClient, private authService: AuthService) {} 42 | 43 | /** 44 | * Method protected by authentication. 45 | * @returns An Observable with a message inside. 46 | */ 47 | getExample(): Observable { 48 | return this.http.get('/api/secret', { headers: this.authService.getAuthHeaders() }); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/app/pages/lazy/reducers/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { createFeatureSelector, createSelector } from '@ngrx/store'; 26 | import * as fromRoot from '../../../reducers'; 27 | import * as fromPageNum from './page-num.reducers'; 28 | 29 | export interface PageNumState { 30 | pageNum: fromPageNum.State; 31 | } 32 | 33 | export interface State extends fromRoot.State { 34 | pageNum: PageNumState; 35 | } 36 | 37 | export const reducers = { 38 | pageNum: fromPageNum.reducer 39 | }; 40 | 41 | export const selectPageNumState = createFeatureSelector('pageNum'); 42 | 43 | export const selectPageNumValState = createSelector(selectPageNumState, (state: PageNumState) => state.pageNum); 44 | 45 | export const getNum = (state: fromPageNum.State) => state.pageNum; 46 | 47 | export const getPageNum = createSelector(selectPageNumValState, getNum); 48 | -------------------------------------------------------------------------------- /src/app/core/core.module.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { NgModule, Optional, SkipSelf } from '@angular/core'; 26 | import { CommonModule } from '@angular/common'; 27 | import { RouterModule } from '@angular/router'; 28 | 29 | import { CORE_SERVICES } from './services/services'; 30 | import { throwIfAlreadyLoaded } from './module-import-guard'; 31 | 32 | /** 33 | * Core module that you can import only one time into the main module. 34 | * If you try to import it again, you'll get a runtime error. 35 | */ 36 | @NgModule({ 37 | imports: [CommonModule, RouterModule], 38 | exports: [], 39 | declarations: [], 40 | providers: [CORE_SERVICES] 41 | }) 42 | export class CoreModule { 43 | constructor( 44 | @Optional() 45 | @SkipSelf() 46 | parentModule: CoreModule 47 | ) { 48 | throwIfAlreadyLoaded(parentModule, 'CoreModule'); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/app/core/reducers/hello-example.reducers.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /* tslint:disable:max-classes-per-file */ 26 | 27 | // This file is used into ../../reducers/index.ts 28 | 29 | import { Action, createReducer, on } from '@ngrx/store'; 30 | 31 | import * as HelloExampleActions from '../actions/hello-example.actions'; 32 | 33 | export const helloKey = 'helloExample'; 34 | 35 | export interface State { 36 | message: string; 37 | } 38 | 39 | const initialState: State = { 40 | message: '' 41 | }; 42 | 43 | const helloExampleReducer = createReducer( 44 | initialState, 45 | on(HelloExampleActions.sayHello, state => ({ 46 | message: 'bye bye!' 47 | })), 48 | on(HelloExampleActions.sayByeBye, state => ({ 49 | message: 'hello!' 50 | })) 51 | ); 52 | 53 | // required to support AOT 54 | export function reducer(state: State | undefined, action: Action) { 55 | return helloExampleReducer(state, action); 56 | } 57 | -------------------------------------------------------------------------------- /src/styles.scss: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2018 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | 24 | // You can add global styles to this file, and also import other style files 25 | @import "theme"; 26 | @import "variables"; 27 | @import "../node_modules/bootstrap/scss/bootstrap"; 28 | 29 | html { 30 | // taken from https://gist.github.com/hsleonis/55712b0eafc9b25f1944 31 | // to improve font rendering 32 | // Adjust font size 33 | font-size: 100%; 34 | // Font variant 35 | font-variant-ligatures: none; 36 | -webkit-font-variant-ligatures: none; 37 | // Smoothing 38 | text-rendering: optimizeLegibility; 39 | -moz-osx-font-smoothing: grayscale; 40 | font-smoothing: antialiased; 41 | -webkit-font-smoothing: antialiased; 42 | text-shadow: rgba(0, 0, 0, .01) 0 0 1px; 43 | } 44 | 45 | body { 46 | font-family: 'Montserrat', sans-serif; 47 | } 48 | 49 | h1 { 50 | color: #333; 51 | } 52 | 53 | h2 { 54 | color: #333; 55 | } 56 | 57 | h3 { 58 | color: #333; 59 | } 60 | 61 | h4 { 62 | color: #333; 63 | } 64 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import 'zone.js/dist/zone'; 26 | import { enableProdMode } from '@angular/core'; 27 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 28 | 29 | import { AppModule } from './app/app.module'; 30 | import { environment } from './environments/environment'; 31 | 32 | import { hmrBootstrap } from './hmr'; 33 | 34 | if (environment.production) { 35 | enableProdMode(); 36 | } 37 | 38 | const bootstrap = () => platformBrowserDynamic().bootstrapModule(AppModule); 39 | 40 | if (environment.hmr) { 41 | // @ts-ignore 42 | if (module['hot']) { 43 | // @ts-ignore 44 | hmrBootstrap(module, bootstrap); 45 | } else { 46 | console.error('HMR is not enabled for webpack-dev-server!'); 47 | console.log('Are you using the --hmr flag for ng serve?'); 48 | } 49 | } else { 50 | document.addEventListener('DOMContentLoaded', () => { 51 | bootstrap().catch(err => console.log(err)); 52 | }); 53 | } 54 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { Component, OnDestroy, OnInit } from '@angular/core'; 26 | import { NavigationEnd, Router } from '@angular/router'; 27 | 28 | import { filter } from 'rxjs/operators'; 29 | import { Subscription } from 'rxjs'; 30 | 31 | declare let ga: Function; 32 | 33 | @Component({ 34 | selector: 'app-root', 35 | templateUrl: './app.component.html', 36 | styleUrls: ['./app.component.scss'] 37 | }) 38 | export class AppComponent implements OnInit, OnDestroy { 39 | private subscription: Subscription; 40 | 41 | constructor(private router: Router) {} 42 | 43 | ngOnInit() { 44 | // this.subscription = this.router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe((event: NavigationEnd) => { 45 | // ga('set', 'page', event.urlAfterRedirects); 46 | // ga('send', 'pageview'); 47 | // }); 48 | } 49 | 50 | ngOnDestroy() { 51 | this.subscription.unsubscribe(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/app/pages/sw/sw.component.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { Component, OnInit } from '@angular/core'; 26 | 27 | import { Observable } from 'rxjs'; 28 | 29 | import { PageHeader } from '../../shared/components/components'; 30 | import { GithubService, GithubUser } from '../../core/services/github.service'; 31 | 32 | /** 33 | * Component with features, template and so on. This is the 34 | * component used to display the service worker page 35 | */ 36 | @Component({ 37 | selector: 'app-sw-page', 38 | styleUrls: ['sw.scss'], 39 | templateUrl: 'sw.html' 40 | }) 41 | export class ServiceWorkerComponent implements OnInit { 42 | pageHeader: PageHeader; 43 | 44 | githubUser: Observable; 45 | 46 | constructor(private githubService: GithubService) { 47 | this.pageHeader = new PageHeader('Service worker example', ''); 48 | } 49 | 50 | ngOnInit() { 51 | // call a real REST service by Github 52 | this.githubUser = this.githubService.getGithubUser(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /servers/node-express-ts/src/db.ts: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2019 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | export const db = [ 24 | { 25 | credential: { 26 | id: 1, 27 | username: 'admin', 28 | password: 'password' 29 | }, 30 | somethingelse: '' 31 | }, 32 | { 33 | credential: { 34 | id: 2, 35 | username: 'admin', 36 | password: 'admin' 37 | }, 38 | somethingelse: '' 39 | } 40 | ]; 41 | 42 | export interface Credential { 43 | id: number; 44 | username: string; 45 | password: string; 46 | } 47 | 48 | export interface Db { 49 | credential: Credential; 50 | somethingelse: string; 51 | } 52 | 53 | export interface Token { 54 | userId: number; 55 | token: string; 56 | } 57 | 58 | // Don't use a const here! 59 | // this is a private variable. 60 | // To access to 'tokens' use get, set and remove to prevent issues 61 | export let tokens: Token[] = []; 62 | 63 | export function getTokens(): Token[] { 64 | return tokens; 65 | } 66 | 67 | export function setTokens(newTokens: Token[]) { 68 | tokens = newTokens; 69 | } 70 | 71 | export function removeTokens() { 72 | tokens = []; 73 | } 74 | -------------------------------------------------------------------------------- /src/_variables.scss: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2018 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | $icon-font-path: "../node_modules/bootstrap-sass/assets/fonts/bootstrap/"; 24 | 25 | // Start with assigning color names to specific hex values. 26 | $white: #fff !default; 27 | $black: #000 !default; 28 | $red: #d91c18 !default; 29 | $orange: #f0ab11 !default; 30 | $yellow: #ffd500 !default; 31 | $green: #00b811 !default; 32 | $blue: #0c06d8 !default; 33 | $teal: #669fde !default; 34 | $pink: #ffa7b7 !default; 35 | $purple: #5c1d7c !default; 36 | 37 | // Create grayscale 38 | $gray-dark: #292b2c !default; 39 | $gray: #464a4c !default; 40 | $gray-light: #636c72 !default; 41 | $gray-lighter: #eceeef !default; 42 | $gray-lightest: #f7f7f9 !default; 43 | 44 | // Reassign color vars to semantic color scheme 45 | $brand-primary: $blue !default; 46 | $brand-success: $green !default; 47 | $brand-info: $teal !default; 48 | $brand-warning: $orange !default; 49 | $brand-danger: $red !default; 50 | $brand-inverse: $gray-dark !default; 51 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "array-type": false, 5 | "arrow-parens": false, 6 | "deprecation": { 7 | "severity": "warn" 8 | }, 9 | "component-class-suffix": true, 10 | "contextual-lifecycle": true, 11 | "directive-class-suffix": true, 12 | "directive-selector": [ 13 | true, 14 | "attribute", 15 | "app", 16 | "camelCase" 17 | ], 18 | "component-selector": [ 19 | true, 20 | "element", 21 | "app", 22 | "kebab-case" 23 | ], 24 | "import-blacklist": [ 25 | true, 26 | "rxjs/Rx" 27 | ], 28 | "interface-name": false, 29 | "max-classes-per-file": false, 30 | "max-line-length": [ 31 | true, 32 | 240 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-consecutive-blank-lines": false, 47 | "no-console": [ 48 | true, 49 | "debug", 50 | "info", 51 | "time", 52 | "timeEnd", 53 | "trace" 54 | ], 55 | "no-empty": false, 56 | "no-inferrable-types": [ 57 | true, 58 | "ignore-params" 59 | ], 60 | "no-non-null-assertion": true, 61 | "no-redundant-jsdoc": true, 62 | "no-switch-case-fall-through": true, 63 | "no-use-before-declare": true, 64 | "no-var-requires": false, 65 | "object-literal-key-quotes": [ 66 | true, 67 | "as-needed" 68 | ], 69 | "object-literal-sort-keys": false, 70 | "ordered-imports": false, 71 | "quotemark": [ 72 | true, 73 | "single" 74 | ], 75 | "trailing-comma": false, 76 | "no-conflicting-lifecycle": true, 77 | "no-host-metadata-property": true, 78 | "no-input-rename": true, 79 | "no-inputs-metadata-property": true, 80 | "no-output-native": true, 81 | "no-output-on-prefix": true, 82 | "no-output-rename": true, 83 | "no-outputs-metadata-property": true, 84 | "template-banana-in-box": true, 85 | "template-no-negated-async": true, 86 | "use-lifecycle-interface": true, 87 | "use-pipe-transform-interface": true 88 | }, 89 | "rulesDirectory": [ 90 | "codelyzer" 91 | ] 92 | } 93 | -------------------------------------------------------------------------------- /src/app/pages/lazy/lazy.module.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { CommonModule } from '@angular/common'; 26 | import { NgModule } from '@angular/core'; 27 | import { RouterModule } from '@angular/router'; 28 | import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; 29 | 30 | import { routes } from './lazy.routes'; 31 | import { LazyComponent } from './lazy.component'; 32 | import { SharedModule } from '../../shared/shared.module'; 33 | 34 | import { StoreModule } from '@ngrx/store'; 35 | import { reducers } from './reducers'; 36 | 37 | console.log('`Lazy` bundle loaded asynchronously'); 38 | 39 | /** 40 | * Lazy loaded module (asynchronously) to reduce the initial boot time required to start the application. 41 | * This module is loaded asynchronously with a network call when the app is ready to use. 42 | */ 43 | @NgModule({ 44 | declarations: [LazyComponent], 45 | imports: [ 46 | CommonModule, 47 | RouterModule.forChild(routes), 48 | NgbModule, 49 | SharedModule, 50 | 51 | // add ngrx to this lazy loaded module 52 | StoreModule.forFeature('pageNum', reducers) 53 | ], 54 | providers: [] 55 | }) 56 | export class LazyModule { 57 | static routes = routes; 58 | } 59 | -------------------------------------------------------------------------------- /.sass-lint.yml: -------------------------------------------------------------------------------- 1 | # inspired by https://gist.github.com/amwelles/293e880843eb800a9942 2 | 3 | files: 4 | include: 'sass/**/*.s+(a|c)ss' 5 | ignore: 6 | - 'coverage/**/*.*' 7 | - 'dist/**/*.*' 8 | 9 | rules: 10 | # Extends 11 | extends-before-mixins: 1 12 | extends-before-declarations: 1 13 | placeholder-in-extend: 0 14 | 15 | # Mixins 16 | mixins-before-declarations: 17 | - 1 18 | - 19 | exclude: 20 | - breakpoint 21 | 22 | # Line Spacing 23 | one-declaration-per-line: 1 24 | empty-line-between-blocks: 0 25 | single-line-per-selector: 1 26 | 27 | # Disallows 28 | no-color-keywords: 0 29 | no-color-literals: 0 30 | no-css-comments: 1 31 | no-debug: 1 32 | no-duplicate-properties: 1 33 | no-empty-rulesets: 1 34 | no-extends: 0 35 | no-ids: 0 36 | no-important: 1 37 | no-invalid-hex: 1 38 | no-mergeable-selectors: 1 39 | no-misspelled-properties: 1 40 | no-qualifying-elements: 41 | - 1 42 | - 43 | allow-element-with-attribute: true 44 | allow-element-with-class: true 45 | no-trailing-zero: 1 46 | no-transition-all: 1 47 | no-url-protocols: 1 48 | no-vendor-prefixes: 1 49 | no-warn: 1 50 | 51 | # Nesting 52 | force-attribute-nesting: 0 53 | force-element-nesting: 1 54 | force-pseudo-nesting: 1 55 | 56 | # Name Formats 57 | function-name-format: 1 58 | mixin-name-format: 1 59 | placeholder-name-format: 1 60 | variable-name-format: 1 61 | 62 | # Style Guide 63 | border-zero: 1 64 | brace-style: 65 | - 1 66 | - 67 | allow-single-line: false 68 | clean-import-paths: 1 69 | empty-args: 1 70 | hex-length: 1 71 | hex-notation: 1 72 | indentation: 1 73 | leading-zero: 1 74 | nesting-depth: 75 | - 1 76 | - 77 | max-depth: 3 78 | property-sort-order: 79 | - 0 80 | - 81 | order: concentric 82 | quotes: 83 | - 1 84 | - 85 | style: double 86 | shorthand-values: 1 87 | url-quotes: 1 88 | variable-for-property: 1 89 | zero-unit: 1 90 | 91 | # Inner Spacing 92 | space-after-comma: 1 93 | space-before-colon: 1 94 | space-after-colon: 1 95 | space-before-brace: 1 96 | space-before-bang: 1 97 | space-after-bang: 1 98 | space-between-parens: 1 99 | 100 | # Final Items 101 | trailing-semicolon: 1 102 | final-newline: 1 103 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { NgModule } from '@angular/core'; 26 | import { PreloadAllModules, RouterModule, Routes } from '@angular/router'; 27 | import { HomeComponent } from './pages/home/home.component'; 28 | import { ProfileComponent } from './pages/profile/profile.component'; 29 | import { ServiceWorkerComponent } from './pages/sw/sw.component'; 30 | import { NotFoundComponent } from './pages/404/not-found.component'; 31 | import { AuthGuard } from './core/services/auth-guard.service'; 32 | 33 | const routes: Routes = [ 34 | { path: '', component: HomeComponent }, 35 | { path: 'home', component: HomeComponent }, 36 | { path: 'profile', component: ProfileComponent, canActivate: [AuthGuard] }, 37 | { path: 'lazy', loadChildren: () => import('./pages/lazy/lazy.module').then(m => m.LazyModule), canActivate: [AuthGuard] }, 38 | { path: 'sw', component: ServiceWorkerComponent, canActivate: [AuthGuard] }, 39 | { path: '**', component: NotFoundComponent } 40 | ]; 41 | 42 | @NgModule({ 43 | imports: [ 44 | RouterModule.forRoot(routes, { 45 | useHash: Boolean(history.pushState) === false, 46 | preloadingStrategy: PreloadAllModules 47 | }) 48 | ], 49 | exports: [RouterModule] 50 | }) 51 | export class AppRoutingModule {} 52 | -------------------------------------------------------------------------------- /servers/node-express-ts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-cli-skeleton-server", 3 | "version": "1.0.0", 4 | "author": "Stefano Cappa", 5 | "description": "Angular skeleton with angular-cli - server side in Typescript", 6 | "license": "MIT", 7 | "homepage": "https://github.com/Ks89", 8 | "private": true, 9 | "repository": "https://github.com/Ks89/angular-cli-skeleton", 10 | "main": "bin/www", 11 | "engines": { 12 | "node": ">=12.16.1", 13 | "npm": ">=6.13.4" 14 | }, 15 | "scripts": { 16 | "start": "npm run build && nodemon dist/server.js", 17 | "build": "npm run build:ts && npm run tslint", 18 | "build:ts": "tsc", 19 | "serve": "node dist/server.js", 20 | "serve:debug": "nodemon --inspect dist/server.js", 21 | "watch:node": "nodemon dist/server.js", 22 | "watch:ts": "tsc -w", 23 | "tslint": "tslint -c tslint.json -p tsconfig.json" 24 | }, 25 | "dependencies": { 26 | "body-parser": "^1.19.0", 27 | "compression": "^1.7.4", 28 | "cookie-parser": "^1.4.4", 29 | "csurf": "^1.10.0", 30 | "dotenv": "^8.2.0", 31 | "expect-ct": "^0.3.0", 32 | "express": "^4.17.1", 33 | "express-content-length-validator": "^1.0.0", 34 | "express-rate-limit": "^5.1.1", 35 | "express-session": "^1.17.0", 36 | "express-slow-down": "^1.3.1", 37 | "helmet": "^3.21.2", 38 | "hpp": "^0.2.2", 39 | "jsonwebtoken": "^8.5.1", 40 | "lodash": "^4.17.15", 41 | "passport": "^0.4.0", 42 | "passport-jwt": "^4.0.0", 43 | "winston": "^3.2.1", 44 | "winston-daily-rotate-file": "^4.4.2" 45 | }, 46 | "devDependencies": { 47 | "@types/body-parser": "^1.17.1", 48 | "@types/compression": "^1.0.1", 49 | "@types/cookie-parser": "^1.4.2", 50 | "@types/csurf": "^1.9.36", 51 | "@types/debug": "^4.1.5", 52 | "@types/express": "^4.17.2", 53 | "@types/express-rate-limit": "^5.0.0", 54 | "@types/express-session": "^1.15.15", 55 | "@types/express-slow-down": "^1.1.1", 56 | "@types/helmet": "0.0.45", 57 | "@types/hpp": "^0.2.1", 58 | "@types/jsonwebtoken": "^8.3.5", 59 | "@types/lodash": "^4.14.144", 60 | "@types/node": "^12.12.5", 61 | "@types/nodemailer": "^6.2.2", 62 | "@types/passport": "^1.0.1", 63 | "@types/passport-jwt": "^3.0.2", 64 | "cpr": "^3.0.1", 65 | "cross-env": "^7.0.2", 66 | "jshint": "^2.10.2", 67 | "nodemon": "^2.0.2", 68 | "pm2": "^4.1.2", 69 | "rimraf": "^3.0.0", 70 | "ts-node": "^8.4.1", 71 | "tslint": "^6.1.0", 72 | "typescript": "^3.7.2" 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /servers/node-express-ts/src/util.ts: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2019 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | import * as _ from 'lodash'; 24 | 25 | export interface JwtPayload { 26 | id: number; 27 | exp: number; 28 | iat: number; 29 | } 30 | 31 | export class JwtInvalidDateError extends Error {} 32 | 33 | export class Utils { 34 | constructor() {} 35 | 36 | static isJwtValidDate(decodedJwtToken: JwtPayload): boolean { 37 | if (!decodedJwtToken.hasOwnProperty('exp')) { 38 | throw new JwtInvalidDateError('Expire date not found'); 39 | } 40 | 41 | // decodedJwtToken.exp is a Float that represents the exp date 42 | // it must be a float, and not a Date 43 | // NB: parseFloat returns NaN if it can't parse a value 44 | if (_.isDate(decodedJwtToken.exp) || _.isNaN(decodedJwtToken.exp)) { 45 | throw new JwtInvalidDateError('Not a float expiration date'); 46 | } 47 | 48 | const convertedDate: Date = new Date(); 49 | convertedDate.setTime(decodedJwtToken.exp); 50 | // console.log('date jwt: ' + convertedDate.getTime() + 51 | // ', formatted: ' + this.getTextFormattedDate(convertedDate)); 52 | // const systemDate = new Date(); 53 | // console.log('systemDate: ' + systemDate.getTime() + 54 | // ', formatted: ' + this.getTextFormattedDate(systemDate)); 55 | // convertedDate > systemDate 56 | return convertedDate.getTime() > new Date().getTime(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/app/shared/components/navbar/navbar.component.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { Component, OnDestroy } from '@angular/core'; 26 | import { Router } from '@angular/router'; 27 | 28 | import { Subscription } from 'rxjs'; 29 | 30 | import { AuthService } from '../../../core/services/auth.service'; 31 | import { ToastrService } from 'ngx-toastr'; 32 | 33 | /** 34 | * Navbar of your application with the main horizontal menu 35 | */ 36 | @Component({ 37 | selector: 'app-navigation', 38 | templateUrl: 'navbar.html', 39 | styleUrls: ['navbar.scss'] 40 | }) 41 | export class NavbarComponent implements OnDestroy { 42 | private logoutSubscription: Subscription; 43 | 44 | constructor(private router: Router, private authService: AuthService, private toastr: ToastrService) {} 45 | 46 | isNavItemActive(location: any) { 47 | return location === this.router.url ? 'active' : ''; 48 | } 49 | 50 | isLoggedIn(): boolean { 51 | return this.authService.isLoggedIn(); 52 | } 53 | 54 | onLogout() { 55 | this.logoutSubscription = this.authService.logout().subscribe( 56 | (resp: any) => { 57 | this.toastr.success('Bye bye!', 'Logout successful', { closeButton: true }); 58 | this.router.navigate(['/']); 59 | }, 60 | err => { 61 | this.toastr.error('Impossible to logout!', 'Logout', { closeButton: true }); 62 | } 63 | ); 64 | } 65 | 66 | ngOnDestroy() { 67 | if (this.logoutSubscription) { 68 | this.logoutSubscription.unsubscribe(); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/app/pages/lazy/lazy.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |

Welcome Roboto font h1

5 |

Welcome Roboto font h2

6 |

Welcome Roboto font h3

7 |

Welcome Roboto font h4

8 | Lazy loaded module 9 | 10 |
11 |
12 |

Please, open your browser's console to see all features of this application!!!

13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 |

Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth 21 | master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh 22 | dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum 23 | iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.

24 |
25 |
26 | 27 | Fancy title 28 | Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. 29 |

Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table 30 | craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl 31 | cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia 32 | yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean 33 | shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero 34 | sint qui sapiente accusamus tattooed echo park.

35 |
36 |
37 | 38 | 39 |

Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth 40 | master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh 41 | dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum 42 | iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.

43 |
44 |
45 |
46 | 47 |
48 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "10" 4 | 5 | os: 6 | - linux 7 | dist: trusty 8 | 9 | # temporary fix to prevent an issue related to chrome headless. I should restore this to false as soon as possible. 10 | # also I should remove these 2 commands from before_script 11 | # 1. sudo chown root /opt/google/chrome/chrome-sandbox 12 | # 2. sudo chmod 4755 /opt/google/chrome/chrome-sandbox 13 | sudo: true 14 | 15 | git: 16 | depth: 3 17 | 18 | branches: 19 | only: master 20 | 21 | env: 22 | global: 23 | - secure: loearYx7bUius1TLj/wQULubiQwrxO0NmE9IyLXZ/blBDtK3cC6XEU5ILfP1jHZKQ5jBePGE3UEmY/e6mPbtrPth1Pbr9dmSPu7l9/wRmSRcVbjSE5uxRfzG1rBkzVaS+ilk2kjYGflYV6SZPJykSP/iWCcc95siEmQeuNIzo90y2ux8+4r/5xCv4BEiVtdu3E0SX5WgmwcI9h/Ztl2Rt3sRtpxOLidu0RuSl+J1PbOIfG7OR1FOcDjXXWdNhawMVeOYvQI+Wfbm/ogvgXBG9Tap7UKjmT3Co65I/xjGwXgryXfRLx2Pf005yQDtio6QUVrNvYdjgxnSzjGaCXr6KPCd1HIWOcEVYzWwid5H/eBuLtpEGqyQgHVOVwjx+Ul6tFjxPhgtpUrDB2/perVIcehFDbvBABOZNUmpAOI1quz0174rskdd+eMAxCAQcU4pZbMKa2/WJi+LG9T9heLad3ckIN1ot6txqToZ6EstxRahwYBUwuiX0SBHdb96IhsDnGWmRZaxEOD4o4Rf1MPk/0CVwY+3n0ah+NV6njq5fbcGkqHG8kDSI1CS8xwAKKzl5jM2QtuNJN6Y3DIPhutn3xp6NDQQvsYCJZeoTn3BeORunMn7z7bZt+hdJtORTUGW1tm8Hyehyx4Ofwn8oH98HODX9rIXXzFP8+vi1fqS4QM= # CODECLIMATE 24 | - secure: GUJeTIIwtr9S8LvRIjiK8YwMJG36jq7E0QLP1F8q2CStGkTWbPYkQ2feZexE6PIeWB32nWJOmdkmqJzeol6LFNPT7Tzm2nCrxf7diBLGf9rcrqD6F/aUdJD+Itf/LZecRWM3yf5dP4R45MzyKSgvX/9zFzRjNMFTP6j5XUoCt+hBI4miL8A897aktT+Sg9hxB901rC21RU2b6r8ByprroJK3W34QDiK6AK3Wira378apNoZn2WhYotsmEOiv4iSzbT/6TkXfrWJbTzFedwH87ZT6ABFS7sLrVYNlU+tbDYke3GhyC0bYeOx1mYpRcSvDa3Em788xqBOs+OE6wao8oHCU983/calPIlVobqtfkzO8z31AKkuCPOEgTKNo84azrunvlWven/MLseTwgYXEgxeS6rBW/v3X3ILg9TWIkxLX6L9lKImKtQ6znGq2FppnmzjsG4rfyYS94hVvdO6ouQaIxrRPgxDc+DbWRQuw854PT2PYKIK7XCZ8x38zCeR1qgLLeVKgIop5W8DGgz27DdA/0WIvK5fZiN7sBZL5spGUnvU72Mf37jNhO8DKJyUH0PQnhBxJvbbta+a3wanblMm2d/E6K5iZdv6DuBuYfvwpzjl5U37XcxPPu5eA/xW4NRHww6SPpiRuXpdDIDJTv9Wtyb6GdlHt7cQojJM+xaw= # COVERALLS 25 | addons: 26 | firefox: latest 27 | apt: 28 | sources: 29 | - google-chrome 30 | packages: 31 | - google-chrome-stable 32 | 33 | matrix: 34 | fast_finish: true 35 | 36 | 37 | before_install: 38 | - source travisci/before_install.sh 39 | install: 40 | - bash travisci/install.sh 41 | after_install: 42 | - npm rebuild node-sass 43 | before_script: 44 | - source travisci/before_script.sh # starts in the same shell 45 | script: 46 | - bash travisci/script.sh 47 | after_success: 48 | - source travisci/after_success.sh 49 | after_script: 50 | - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT 51 | 52 | cache: 53 | apt: true 54 | bundler: true 55 | directories: 56 | - ./node_modules 57 | - ./servers/node-express-js/node_modules 58 | - ./servers/node-express-ts/node_modules 59 | - ./servers/node-koa-js/node_modules 60 | - '$HOME/.sonar/cache' 61 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | working_directory: ~/my-project 5 | docker: 6 | - image: circleci/node:latest-browsers # before was 7.10.0-browsers 7 | # Environment variable for all commands executed in the primary container 8 | environment: 9 | NODE_ENV: test 10 | CI: yes 11 | steps: 12 | - checkout 13 | - run: 14 | name: npm-install-global 15 | command: sudo npm install -g codeclimate-test-reporter 16 | - restore_cache: 17 | key: my-project-{{ .Branch }}-{{ checksum "package.json" }} 18 | - run: 19 | name: node-sass-clean 20 | command: npm rebuild node-sass --force 21 | - run: 22 | name: npm-install 23 | command: npm install 24 | - save_cache: 25 | key: my-project-{{ .Branch }}-{{ checksum "package.json" }} 26 | paths: 27 | - "node_modules" 28 | # - "servers/node-express-js/node_modules" 29 | # - "servers/node-express-ts/node_modules" 30 | # - "servers/node-koa-js/node_modules" 31 | - run: 32 | name: run-build-dev 33 | command: npm run build:dev 34 | - run: 35 | name: run-clean 36 | command: npm run clean # clean before the real production build 37 | - run: 38 | name: run-build-prod 39 | command: npm run build:prod 40 | # - run: 41 | # name: run-build-prod-ssr 42 | # command: npm run build:ssr 43 | # - run: 44 | # name: run-build-prod-prerender 45 | # command: npm run build:prerender 46 | - run: 47 | name: run-test 48 | #xvfb-run is used to run npm run to run a command using a virtual screen, which is needed by Chrome. 49 | command: xvfb-run -a npm run test:ci 50 | - run: 51 | name: Install Chromedriver latest version 52 | command: | 53 | sudo apt-get update 54 | sudo apt-get install lsb-release 55 | curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb 56 | sudo dpkg -i google-chrome.deb 57 | sudo sed -i 's|HERE/chrome"|HERE/chrome" --disable-setuid-sandbox|g' /opt/google/chrome/google-chrome 58 | rm google-chrome.deb 59 | - run: 60 | name: run-webdriver-update 61 | command: npm run webdriver:update 62 | - run: 63 | name: run-e2e 64 | command: xvfb-run -a npm run e2e:ci 65 | - run: 66 | name: run-docs 67 | command: npm run docs 68 | - run: 69 | name: run-codeclimate 70 | command: npm run codeclimate 71 | - run: 72 | name: run-coveralls 73 | command: npm run coveralls 74 | -------------------------------------------------------------------------------- /src/app/core/services/github.service.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | /* tslint:disable:max-classes-per-file variable-name */ 26 | 27 | import { Injectable } from '@angular/core'; 28 | import { HttpClient } from '@angular/common/http'; 29 | 30 | import { Observable } from 'rxjs'; 31 | 32 | export class GithubUser { 33 | constructor( 34 | public login: string, 35 | public id: number, 36 | public url: string, 37 | public repos_url: string, 38 | public name: string | void, 39 | public company: string | void, 40 | public location: string | void 41 | ) {} 42 | } 43 | 44 | export class GithubOrg { 45 | constructor( 46 | public login: string | void, 47 | public id: number | void, 48 | public url: string | void, 49 | public repos_url: string | void, 50 | public events_url: string | void, 51 | public hooks_url: string | void, 52 | public issues_url: string | void, 53 | public members_url: string | void, 54 | public public_members_url: string | void, 55 | public avatar_url: string | void, 56 | public description: string | void 57 | ) {} 58 | } 59 | 60 | /** 61 | * Example of a service to retrieve remote data from https://api.github.com/users/Ks89 62 | */ 63 | @Injectable() 64 | export class GithubService { 65 | constructor(private http: HttpClient) {} 66 | 67 | /** 68 | * Method to get my Github profile asynchronously using Github's apis. 69 | * @returns A Observable with data inside. 70 | */ 71 | getGithubUser(): Observable { 72 | return this.http.get('https://api.github.com/users/Ks89'); 73 | } 74 | 75 | /** 76 | * Method to get all organizations of my Github profile asynchronously using Github's apis. 77 | * @returns A Observable with data inside. 78 | */ 79 | getGithubKs89Organizations(): Observable { 80 | return this.http.get('https://api.github.com/users/Ks89/orgs'); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 3 | import { BrowserModule } from '@angular/platform-browser'; 4 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 5 | import { HttpClientModule, HttpClientXsrfModule } from '@angular/common/http'; 6 | import { ServiceWorkerModule } from '@angular/service-worker'; 7 | import { RouterModule } from '@angular/router'; 8 | 9 | import { ToastrModule } from 'ngx-toastr'; 10 | import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; 11 | 12 | import { StoreModule } from '@ngrx/store'; 13 | import { StoreDevtoolsModule } from '@ngrx/store-devtools'; 14 | import { ROOT_REDUCERS, metaReducers } from './reducers'; 15 | 16 | import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; 17 | 18 | import { environment } from '../environments/environment'; 19 | 20 | import { AppRoutingModule } from './app-routing.module'; 21 | import { SharedModule } from './shared/shared.module'; 22 | import { CoreModule } from './core/core.module'; 23 | import { COMPONENTS } from './pages/components'; 24 | import { AppComponent } from './app.component'; 25 | 26 | @NgModule({ 27 | declarations: [AppComponent, COMPONENTS], 28 | imports: [ 29 | // Add .withServerTransition() to support Universal rendering. 30 | // The application ID can be any identifier which is unique on 31 | // the page. 32 | BrowserModule.withServerTransition({ appId: 'my-app' }), 33 | BrowserAnimationsModule, 34 | 35 | HttpClientModule, 36 | HttpClientXsrfModule, 37 | 38 | FormsModule, 39 | ReactiveFormsModule, 40 | RouterModule, 41 | 42 | NgbModule, 43 | ToastrModule.forRoot(), // ToastrModule added 44 | 45 | FontAwesomeModule, 46 | 47 | // if you enabled service workers inside .angular-cli.json, 48 | // I suggest to use it, only for the production build 49 | // TO TEST SERVICE WORKERS IN YOUR BROWSER YOU MUST: 50 | // 1. build with `npm run build:prod` (not serve:prod) 51 | // 2. run with `lite-server` 52 | // 3. navigate the application 53 | // 4. disable network and cache from chrome dev tools (network tab) 54 | // 5. you should able to navigate the app and in chrome dev tools (network tab), all 55 | // requests should come from service workers (not cache and not network) 56 | // I suggest also to check application tab -> Service Workers to see if is running or not 57 | ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production }), 58 | 59 | // third party (ngrx) 60 | StoreModule.forRoot(ROOT_REDUCERS, { 61 | metaReducers, 62 | runtimeChecks: { 63 | strictStateImmutability: true, 64 | strictActionImmutability: true, 65 | strictStateSerializability: true, 66 | strictActionSerializability: true 67 | } 68 | }), 69 | StoreDevtoolsModule.instrument({ 70 | name: 'Ks89 example App', 71 | logOnly: environment.production 72 | }), 73 | 74 | CoreModule, 75 | SharedModule, 76 | AppRoutingModule, 77 | ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production }) 78 | ], 79 | providers: [], 80 | bootstrap: [AppComponent] 81 | }) 82 | export class AppModule {} 83 | -------------------------------------------------------------------------------- /servers/node-express-js/bin/www: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // MIT License 4 | // 5 | // Copyright (c) 2017-2019 Stefano Cappa 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | // SOFTWARE. 24 | 25 | 'use strict'; 26 | 27 | const config = require('../src/config'); 28 | const app = require('../app'); 29 | const debug = require('debug')('ks89:server'); 30 | const http = require('http'); 31 | 32 | /** 33 | * Get port from environment and store in Express. 34 | */ 35 | let port = normalizePort(config.PORT || '3000'); 36 | console.log(`Port is: ${port}`); 37 | app.set('port', port); 38 | 39 | /** 40 | * Create HTTP server. 41 | */ 42 | let server = http.createServer(app); 43 | 44 | /** 45 | * Listen on provided port, on all network interfaces. 46 | */ 47 | server.listen(port); 48 | server.on('error', onError); 49 | server.on('listening', onListening); 50 | 51 | /** 52 | * Normalize a port into a number, string, or false. 53 | */ 54 | function normalizePort(val) { 55 | let port = parseInt(val, 10); 56 | 57 | if (isNaN(port)) { 58 | // named pipe 59 | return val; 60 | } 61 | 62 | if (port >= 0) { 63 | // port number 64 | return port; 65 | } 66 | 67 | return false; 68 | } 69 | 70 | /** 71 | * Event listener for HTTP server "error" event. 72 | */ 73 | function onError(error) { 74 | if (error.syscall !== 'listen') { 75 | throw error; 76 | } 77 | 78 | let bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; 79 | 80 | // handle specific listen errors with friendly messages 81 | switch (error.code) { 82 | case 'EACCES': 83 | console.error(bind + ' requires elevated privileges'); 84 | process.exit(1); 85 | break; 86 | case 'EADDRINUSE': 87 | console.error(bind + ' is already in use'); 88 | process.exit(1); 89 | break; 90 | default: 91 | throw error; 92 | } 93 | } 94 | 95 | /** 96 | * Event listener for HTTP server "listening" event. 97 | */ 98 | function onListening() { 99 | let addr = server.address(); 100 | let bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; 101 | debug(`Listening on ${bind}`); 102 | console.log(`Listening on ${bind}`); 103 | } 104 | -------------------------------------------------------------------------------- /src/app/pages/home/home.component.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { Component, OnDestroy } from '@angular/core'; 26 | import { FormBuilder, FormGroup, Validators } from '@angular/forms'; 27 | import { Router } from '@angular/router'; 28 | import { Subscription } from 'rxjs'; 29 | 30 | import { AuthService } from '../../core/services/auth.service'; 31 | import { ToastrService } from 'ngx-toastr'; 32 | 33 | /** 34 | * Component to login 35 | */ 36 | @Component({ 37 | selector: 'app-home-page', 38 | styleUrls: ['home.scss'], 39 | templateUrl: 'home.html' 40 | }) 41 | export class HomeComponent implements OnDestroy { 42 | formModel: FormGroup; 43 | 44 | private loginSubscription: Subscription; 45 | 46 | constructor(private authService: AuthService, private router: Router, private toastr: ToastrService) { 47 | // STILL USELESS BECAUSE ANGULAR 9.0.0 DOESN'T SUPPORT STRING EXATRACTIONS IN XLF FILES IF ADDED IN TYPESCRIPT FILES WITH THE NEW $localize 48 | //$localize `some string to localize`; 49 | 50 | const fb = new FormBuilder(); 51 | this.formModel = fb.group({ 52 | username: [null, Validators.required], 53 | password: [null, Validators.required] 54 | }); 55 | } 56 | 57 | onLogin() { 58 | if (!this.formModel.valid) { 59 | this.toastr.error('Both username and password are mandatory!', 'Login failed!', { closeButton: true }); 60 | return; 61 | } 62 | 63 | this.loginSubscription = this.authService 64 | .login({ 65 | username: this.formModel.value.username, 66 | password: this.formModel.value.password 67 | }) 68 | .subscribe( 69 | resp => { 70 | this.toastr.success('Welcome!', 'Login successful!', { closeButton: true }); 71 | this.router.navigate(['/profile']); 72 | }, 73 | err => { 74 | this.toastr.error('Username or password not valid!', 'Login error!', { closeButton: true }); 75 | } 76 | ); 77 | } 78 | 79 | ngOnDestroy() { 80 | // unsubscribe to all Subscriptions to prevent memory leaks and wrong behaviour 81 | if (this.loginSubscription) { 82 | this.loginSubscription.unsubscribe(); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /servers/node-express-ts/src/server.ts: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2019 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | // 23 | 24 | import debug from 'debug'; 25 | debug('ks89:server'); 26 | 27 | import http, { Server } from 'http'; 28 | 29 | import app from './app'; 30 | import * as config from './config'; 31 | import { AddressInfo } from 'net'; 32 | 33 | /** 34 | * Get port from environment and store in Express. 35 | */ 36 | const port: number | string = normalizePort(config.PORT || '3000'); 37 | console.log(`Port is: ${port}`); 38 | app.set('port', port); 39 | 40 | /** 41 | * Create HTTP server. 42 | */ 43 | const server: Server = http.createServer(app); 44 | 45 | /** 46 | * Listen on provided port, on all network interfaces. 47 | */ 48 | server.listen(port); 49 | server.on('error', onError); 50 | server.on('listening', onListening); 51 | 52 | /** 53 | * Normalize a port into a number, string, or false. 54 | */ 55 | function normalizePort(val: string): number | string { 56 | const port: number = parseInt(val, 10); 57 | 58 | if (isNaN(port)) { 59 | // named pipe 60 | return val; 61 | } 62 | 63 | if (port >= 0) { 64 | // port number 65 | return port; 66 | } 67 | 68 | return 'Unknown port'; 69 | } 70 | 71 | /** 72 | * Event listener for HTTP server "error" event. 73 | */ 74 | function onError(error: any) { 75 | if (error.syscall !== 'listen') { 76 | throw error; 77 | } 78 | 79 | const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; 80 | 81 | // handle specific listen errors with friendly messages 82 | switch (error.code) { 83 | case 'EACCES': 84 | console.error(bind + ' requires elevated privileges'); 85 | process.exit(1); 86 | break; 87 | case 'EADDRINUSE': 88 | console.error(bind + ' is already in use'); 89 | process.exit(1); 90 | break; 91 | default: 92 | throw error; 93 | } 94 | } 95 | 96 | /** 97 | * Event listener for HTTP server "listening" event. 98 | */ 99 | function onListening() { 100 | const addr: AddressInfo = server.address(); 101 | debug(`Listening on ${addr.port}`); 102 | console.log(`Listening on ${addr.port}`); 103 | } 104 | 105 | export default server; 106 | -------------------------------------------------------------------------------- /prerender.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | // Load zone.js for the server. 26 | import 'zone.js/dist/zone-node'; 27 | import 'reflect-metadata'; 28 | 29 | import { renderModuleFactory } from '@angular/platform-server'; 30 | import { enableProdMode } from '@angular/core'; 31 | 32 | import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs'; 33 | import { join } from 'path'; 34 | 35 | // Import module map for lazy loading 36 | import { ROUTES } from './static.paths'; 37 | 38 | const domino = require('domino'); 39 | 40 | // Faster server renders w/ Prod mode (dev mode never needed) 41 | enableProdMode(); 42 | 43 | // Load the index.html file containing referances to your application bundle. 44 | const index = readFileSync(join('client', 'index.html'), 'utf8'); 45 | const win = domino.createWindow(index); 46 | 47 | global['window'] = win; 48 | Object.defineProperty(win.document.body.style, 'transform', { 49 | value: () => { 50 | return { 51 | enumerable: true, 52 | configurable: true 53 | }; 54 | } 55 | }); 56 | global['document'] = win.document; 57 | global['CSS'] = null; 58 | // WORKAROUND until SSR will support all third-party libraries 59 | global['Mousetrap'] = function() { 60 | this.reset = function() {}; 61 | }; 62 | 63 | const BROWSER_FOLDER = join(process.cwd(), 'client'); 64 | 65 | // * NOTE :: leave this as require() since this file is built Dynamically from webpack 66 | const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/client-server/main'); 67 | 68 | import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader'; 69 | 70 | let previousRender = Promise.resolve(); 71 | 72 | // Iterate each route path 73 | ROUTES.forEach(route => { 74 | const fullPath = join(BROWSER_FOLDER, route); 75 | 76 | // Make sure the directory structure is there 77 | if (!existsSync(fullPath)) { 78 | mkdirSync(fullPath); 79 | } 80 | 81 | // Writes rendered HTML to index.html, replacing the file if it already exists. 82 | previousRender = previousRender 83 | .then(_ => 84 | renderModuleFactory(AppServerModuleNgFactory, { 85 | document: index, 86 | url: route, 87 | extraProviders: [provideModuleMap(LAZY_MODULE_MAP)] 88 | }) 89 | ) 90 | .then(html => writeFileSync(join(fullPath, 'index.html'), html)); 91 | }); 92 | -------------------------------------------------------------------------------- /src/app/reducers/index.ts: -------------------------------------------------------------------------------- 1 | // based on https://github.com/ngrx/platform/blob/48a2381c212d5dd3fa2b9435776c1aaa60734235/example-app/app/reducers/index.ts 2 | 3 | /* 4 | * MIT License 5 | * 6 | * Copyright (c) 2017-2019 Stefano Cappa 7 | * Copyright (c) 2017 Brandon Roberts, Mike Ryan, Victor Savkin, Rob Wormald 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in all 17 | * copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | * SOFTWARE. 26 | */ 27 | 28 | import { createSelector, createFeatureSelector, ActionReducer, MetaReducer, Action, ActionReducerMap } from '@ngrx/store'; 29 | import { environment } from '../../environments/environment'; 30 | 31 | import * as fromHelloExample from '../core/reducers/hello-example.reducers'; 32 | 33 | import { InjectionToken } from '@angular/core'; 34 | 35 | /** 36 | * As mentioned, we treat each reducer like a table in a database. This means 37 | * our top level state interface is just a map of keys to inner state types. 38 | */ 39 | export interface State { 40 | [fromHelloExample.helloKey]: fromHelloExample.State; 41 | } 42 | 43 | /** 44 | * Our state is composed of a map of action reducer functions. 45 | * These reducer functions are called with each dispatched action 46 | * and the current or initial state and return a new immutable state. 47 | */ 48 | export const ROOT_REDUCERS = new InjectionToken>('Root reducers token', { 49 | factory: () => ({ 50 | [fromHelloExample.helloKey]: fromHelloExample.reducer 51 | }) 52 | }); 53 | 54 | // console.log all actions 55 | export function logger(reducer: ActionReducer): ActionReducer { 56 | return (state, action) => { 57 | const result = reducer(state, action); 58 | console.groupCollapsed(action.type); 59 | console.log('prev state', state); 60 | console.log('action', action); 61 | console.log('next state', result); 62 | console.groupEnd(); 63 | return result; 64 | }; 65 | } 66 | 67 | /** 68 | * By default, @ngrx/store uses combineReducers with the reducer map to compose 69 | * the root meta-reducer. To add more meta-reducers, provide an array of meta-reducers 70 | * that will be composed to form the root meta-reducer. 71 | */ 72 | export const metaReducers: MetaReducer[] = !environment.production ? [logger] : []; 73 | 74 | export const selectHelloExampleState = createFeatureSelector(fromHelloExample.helloKey); 75 | export const selectHelloMessage = createSelector(selectHelloExampleState, (state: fromHelloExample.State) => state.message); 76 | -------------------------------------------------------------------------------- /server.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | // These are important and needed before anything else 26 | import 'zone.js/dist/zone-node'; 27 | import 'reflect-metadata'; 28 | 29 | import { renderModuleFactory } from '@angular/platform-server'; 30 | import { enableProdMode } from '@angular/core'; 31 | 32 | import * as express from 'express'; 33 | import * as compression from 'compression'; 34 | import { join } from 'path'; 35 | import { readFileSync } from 'fs'; 36 | 37 | const domino = require('domino'); 38 | 39 | // Faster server renders w/ Prod mode (dev mode never needed) 40 | enableProdMode(); 41 | 42 | // Our index.html we'll use as our template 43 | const template = readFileSync(join(process.cwd(), 'dist', 'client', 'index.html')).toString(); 44 | const win = domino.createWindow(template); 45 | 46 | global['window'] = win; 47 | Object.defineProperty(win.document.body.style, 'transform', { 48 | value: () => { 49 | return { 50 | enumerable: true, 51 | configurable: true 52 | }; 53 | } 54 | }); 55 | global['document'] = win.document; 56 | global['CSS'] = null; 57 | 58 | // WORKAROUND until SSR will support all third-party libraries 59 | global['Mousetrap'] = function() { 60 | this.reset = function() {}; 61 | }; 62 | 63 | const PORT = process.env.PORT || 3000; 64 | const DIST_FOLDER = join(process.cwd(), 'dist', 'client'); 65 | 66 | // * NOTE :: leave this as require() since this file is built Dynamically from webpack 67 | const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./dist/client-server/main'); 68 | 69 | import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader'; 70 | 71 | const app = express(); 72 | app.use(compression()); 73 | 74 | app.engine('html', (_, options, callback) => { 75 | renderModuleFactory(AppServerModuleNgFactory, { 76 | // Our index.html 77 | document: template, 78 | url: options.req.url, 79 | // DI so that we can get lazy-loading to work differently (since we need it to just instantly render it) 80 | extraProviders: [provideModuleMap(LAZY_MODULE_MAP)] 81 | }).then(html => { 82 | callback(null, html); 83 | }); 84 | }); 85 | 86 | app.set('view engine', 'html'); 87 | app.set('views', DIST_FOLDER); 88 | 89 | app.get('*.*', express.static(DIST_FOLDER)); 90 | app.get('*', (req, res) => { 91 | global['navigator'] = req['headers']['user-agent']; 92 | res.render('index', { req }); 93 | }); 94 | 95 | app.listen(PORT, () => console.log(`Listening on http://localhost:${PORT}`)); 96 | -------------------------------------------------------------------------------- /src/app/pages/lazy/lazy.component.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { Component, OnDestroy, OnInit } from '@angular/core'; 26 | import { Observable, Subscription } from 'rxjs'; 27 | 28 | import { PageHeader } from '../../shared/components/components'; 29 | import { ExampleService } from '../../core/services/example.service'; 30 | 31 | import { Store, select } from '@ngrx/store'; 32 | import * as fromPageNum from './reducers'; 33 | import { setPageNum } from './actions/page-num.actions'; 34 | 35 | console.log('`Lazy` component loaded asynchronously'); 36 | 37 | /** 38 | * Component of the lazy loaded module for the app SPA 39 | */ 40 | @Component({ 41 | selector: 'app-lazy-page', 42 | templateUrl: 'lazy.html', 43 | styleUrls: ['lazy.scss'] 44 | }) 45 | export class LazyComponent implements OnInit, OnDestroy { 46 | pageHeader: PageHeader; 47 | 48 | private pageNum$: Observable; 49 | private pageNumSubscription: Subscription; 50 | private exampleServiceSubscription: Subscription; 51 | 52 | constructor(private exampleService: ExampleService, private store: Store) { 53 | this.pageHeader = new PageHeader('LAZY', ''); 54 | 55 | this.pageNum$ = this.store.pipe(select(fromPageNum.getPageNum)); 56 | 57 | // example of ngrx-store's usage 58 | // subscribe to pageNum (a number, for instance the current page of a table with pagination) 59 | // initially is 0, after it will be 4 (see below) -> this is only an example for demonstration purpose 60 | this.pageNumSubscription = this.pageNum$.subscribe((val: number) => { 61 | console.log(`Page num retrieved from ngrx-store is ${val}`); 62 | }); 63 | } 64 | 65 | ngOnInit() { 66 | // call a service and dispatch an action to ngrx to trigger a new event into pageNum$ Observable 67 | this.exampleServiceSubscription = this.exampleService.getExample().subscribe((val: any) => { 68 | console.log(`Result of getExample`, val); 69 | 70 | // dispatch the setPageNum action with '4' as payload 71 | this.store.dispatch(setPageNum({ payload: 4 })); // I chose a constant value for this example :) 72 | }); 73 | } 74 | 75 | ngOnDestroy() { 76 | console.log('Destroy called'); 77 | 78 | // unsubscribe to all Subscriptions to prevent memory leaks and wrong behaviour 79 | if (this.pageNumSubscription) { 80 | this.pageNumSubscription.unsubscribe(); 81 | } 82 | if (this.exampleServiceSubscription) { 83 | this.exampleServiceSubscription.unsubscribe(); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/app/core/services/auth.service.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2017-2019 Stefano Cappa 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | import { Inject, Injectable, PLATFORM_ID } from '@angular/core'; 26 | import { HttpClient, HttpHeaders } from '@angular/common/http'; 27 | import { isPlatformBrowser } from '@angular/common'; 28 | 29 | import { Observable } from 'rxjs'; 30 | import { tap } from 'rxjs/operators'; 31 | 32 | export interface User { 33 | username: string; 34 | password: string; 35 | } 36 | 37 | export interface AuthResponse { 38 | message?: string; 39 | token?: string; 40 | } 41 | 42 | const TOKEN_NAME = 'token'; 43 | 44 | @Injectable() 45 | export class AuthService { 46 | token: string; 47 | 48 | constructor(private http: HttpClient, @Inject(PLATFORM_ID) private platformId: Object) { 49 | // get existing token from local storage (if available/previously logged in) 50 | this.token = this.getToken(); 51 | } 52 | 53 | isLoggedIn(tokenName: string = TOKEN_NAME): boolean { 54 | if (isPlatformBrowser(this.platformId)) { 55 | return !!localStorage.getItem(tokenName); 56 | } else { 57 | return false; 58 | } 59 | } 60 | 61 | getToken(tokenName: string = TOKEN_NAME): string | null { 62 | if (isPlatformBrowser(this.platformId)) { 63 | return localStorage.getItem(tokenName); 64 | } else { 65 | return null; 66 | } 67 | } 68 | 69 | setToken(token: string, tokenName: string = TOKEN_NAME) { 70 | if (isPlatformBrowser(this.platformId)) { 71 | localStorage.setItem(tokenName, token); 72 | } 73 | } 74 | 75 | removeToken(tokenName: string = TOKEN_NAME) { 76 | if (isPlatformBrowser(this.platformId)) { 77 | localStorage.removeItem(tokenName); 78 | } 79 | } 80 | 81 | login(user: User): Observable { 82 | return this.http.post('/api/login', user).pipe( 83 | tap((resp: AuthResponse) => { 84 | // login successful if there's a jwt token in the response 85 | const token = resp.token; 86 | if (token) { 87 | this.token = token; 88 | // store token in local storage to keep user logged in 89 | this.setToken(token); 90 | } 91 | }) 92 | ); 93 | } 94 | 95 | logout(): Observable { 96 | return this.http.get('/api/logout', { headers: this.getAuthHeaders() }).pipe(tap(() => this.removeToken())); 97 | } 98 | 99 | getAuthHeaders(): HttpHeaders { 100 | let headers = new HttpHeaders(); 101 | headers = headers.set('Authorization', 'Bearer ' + this.getToken()); 102 | return headers; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | const os = require('os'); 5 | 6 | console.log(`Starting Karma with isCI=${!!isCI()}`); 7 | 8 | function isCI() { 9 | return process.env.CI || process.env.APPVEYOR || process.env.TRAVIS || process.env.CIRCLECI; 10 | } 11 | 12 | function getBrowsers() { 13 | if (process.env.CI) { 14 | if (process.env.APPVEYOR) { 15 | // variable defined by APPVEYOR itself 16 | // only for AppVeyor 17 | return ['Chrome' /*, 'Firefox', 'IE'*/]; 18 | } else if (process.env.TRAVIS) { 19 | // variable defined by TRAVIS itself 20 | return ['ChromeHeadless', 'Chrome' /*, 'Firefox'*/]; 21 | } else if (process.env.CIRCLECI) { 22 | // variable defined by CIRCLECI itself 23 | return ['ChromeHeadless', 'Chrome' /*, 'Firefox'*/]; 24 | } 25 | } else { 26 | switch (os.platform()) { 27 | case 'win32': // Windows 28 | return ['ChromeHeadless', 'Chrome' /*, 'Firefox', 'IE','Edge'*/]; 29 | case 'darwin': // macOS 30 | return ['ChromeHeadless', 'Chrome' /*, 'Firefox'*/ /*, 'Safari'*/]; 31 | default: 32 | // other (linux, freebsd, openbsd, sunos, aix) 33 | return ['ChromeHeadless', 'Chrome' /*, 'Firefox'*/]; 34 | } 35 | } 36 | } 37 | 38 | module.exports = function(config) { 39 | config.set({ 40 | basePath: '', 41 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 42 | plugins: [ 43 | require('karma-jasmine'), 44 | require('karma-chrome-launcher'), 45 | require('karma-jasmine-html-reporter'), 46 | require('karma-coverage-istanbul-reporter'), 47 | require('karma-coverage'), 48 | require('karma-mocha-reporter'), 49 | require('@angular-devkit/build-angular/plugins/karma') 50 | ], 51 | client: { 52 | clearContext: false // leave Jasmine Spec Runner output visible in browser 53 | }, 54 | 55 | /* 56 | * when angular-cli's coverage is enabled 57 | * - mocha is used to show mocha results in console (ps you cannot add both progress and mocha at the same time) 58 | * - coverage is used to show coverage result in console 59 | * - coverage-istanbul is recommended by angular-cli and used to emit html and lcov 60 | * - sonrqube is used to build the report used by SonarQube 61 | * when is disabled 62 | * - progress is an alternative of mocha (default and recommended by angular-cli 63 | * - kjhtml is used to show karma progress inside the browser 64 | * 65 | */ 66 | reporters: ['mocha', 'coverage', 'coverage-istanbul'], 67 | port: 9876, 68 | colors: true, 69 | logLevel: config.LOG_INFO, 70 | autoWatch: true, 71 | browsers: getBrowsers(), 72 | singleRun: false, 73 | 74 | // required by coverage-istanbul 75 | coverageIstanbulReporter: { 76 | dir: require('path').join(__dirname, 'coverage'), 77 | reports: ['html', 'lcovonly'], 78 | fixWebpackSourcePaths: true 79 | }, 80 | 81 | // required by karma-coverage to show code coverage in console 82 | coverageReporter: { 83 | type: 'text-summary' 84 | }, 85 | 86 | customLaunchers: { 87 | ChromeHeadless: { 88 | base: 'Chrome', 89 | flags: [ 90 | '--no-sandbox', 91 | // See https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md 92 | '--headless', 93 | '--disable-gpu', 94 | // Without a remote debugging port, Google Chrome exits immediately. 95 | ' --remote-debugging-port=9222' 96 | ] 97 | } 98 | }, 99 | 100 | // For AppVeyor and TravisCI to prevent timeouts 101 | browserNoActivityTimeout: 60000 102 | }); 103 | }; 104 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | * Load `$localize` onto the global scope - used if i18n tags appear in Angular templates. 3 | */ 4 | import '@angular/localize/init'; 5 | /* 6 | * MIT License 7 | * 8 | * Copyright (c) 2017-2019 Stefano Cappa 9 | * 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy 11 | * of this software and associated documentation files (the "Software"), to deal 12 | * in the Software without restriction, including without limitation the rights 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 14 | * copies of the Software, and to permit persons to whom the Software is 15 | * furnished to do so, subject to the following conditions: 16 | * 17 | * The above copyright notice and this permission notice shall be included in all 18 | * copies or substantial portions of the Software. 19 | * 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | * SOFTWARE. 27 | */ 28 | 29 | /** 30 | * This file includes polyfills needed by Angular and is loaded before the app. 31 | * You can add your own extra polyfills to this file. 32 | * 33 | * This file is divided into 2 sections: 34 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 35 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 36 | * file. 37 | * 38 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 39 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 40 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 41 | * 42 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html 43 | */ 44 | 45 | /*************************************************************************************************** 46 | * BROWSER POLYFILLS 47 | */ 48 | 49 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 50 | // import 'core-js/es6/symbol'; 51 | // import 'core-js/es6/object'; 52 | // import 'core-js/es6/function'; 53 | // import 'core-js/es6/parse-int'; 54 | // import 'core-js/es6/parse-float'; 55 | // import 'core-js/es6/number'; 56 | // import 'core-js/es6/math'; 57 | // import 'core-js/es6/string'; 58 | // import 'core-js/es6/date'; 59 | // import 'core-js/es6/array'; 60 | // import 'core-js/es6/regexp'; 61 | // import 'core-js/es6/map'; 62 | // import 'core-js/es6/weak-map'; 63 | // import 'core-js/es6/set'; 64 | 65 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 66 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 67 | 68 | /** IE10 and IE11 requires the following for the Reflect API. */ 69 | // import 'core-js/es6/reflect'; 70 | 71 | /** Evergreen browsers require these. **/ 72 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. 73 | // Removed because I'm always using AOT!!!! 74 | // import 'core-js/es7/reflect'; 75 | 76 | /** 77 | * Required to support Web Animations `@angular/platform-browser/animations`. 78 | * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation 79 | **/ 80 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 81 | 82 | /*************************************************************************************************** 83 | * Zone JS is required by default for Angular itself. 84 | */ 85 | import 'zone.js/dist/zone'; // Included with Angular CLI. 86 | 87 | /*************************************************************************************************** 88 | * APPLICATION IMPORTS 89 | */ 90 | -------------------------------------------------------------------------------- /servers/node-koa-js/src/config.js: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2019 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | 'use strict'; 24 | 25 | const path = require('path'); 26 | 27 | const notInCI = process.env.CI !== 'yes' && process.env.CI !== true; 28 | console.log(`Use dotenv condition is: ${notInCI}, because I cannot use dotenv with CI, so I have to skip it`); 29 | 30 | if (notInCI === true) { 31 | console.log('Initializing dotenv (requires .env/.env_prod file)'); 32 | let dotenvName = null; 33 | switch (process.env.NODE_ENV) { 34 | case 'development': 35 | console.log('dotenv read: .env'); 36 | dotenvName = '.env'; 37 | break; 38 | case 'test': 39 | console.log('dotenv read: .env (you are running with NODE_ENV=test)'); 40 | dotenvName = '.env'; 41 | break; 42 | default: 43 | case 'production': 44 | console.log('dotenv read: .env_prod'); 45 | dotenvName = '.env_prod'; 46 | break; 47 | } 48 | 49 | const dotenvAbsolutePath = path.join(__dirname, '../' + dotenvName); 50 | 51 | const dotenv = require('dotenv').config({ 52 | path: dotenvAbsolutePath 53 | }); 54 | if (dotenv.error) { 55 | throw dotenv.error; 56 | } 57 | console.log(`dotenv parsed with NODE_ENV=${process.env.NODE_ENV}`, dotenv.parsed); 58 | } 59 | 60 | // ATTENTION!!! 61 | // don't use here logger.js because it requires config fully initialized 62 | 63 | module.exports = { 64 | isProd: () => process.env.NODE_ENV === 'production', 65 | isTest: () => process.env.NODE_ENV === 'test', 66 | isCI: () => process.env.CI === 'yes' || process.env.CI === true, 67 | 68 | NODE_ENV: process.env.NODE_ENV || 'development', 69 | CI: process.env.CI || 'yes', 70 | 71 | FRONT_END_PATH: process.env.FRONT_END_PATH, 72 | PORT: process.env.PORT || process.env.NODE_ENV === 'production' ? 80 : 3000, 73 | 74 | LOG_FOLDER: process.env.LOG_FOLDER, 75 | 76 | // Jwt config for apis server <-> client 77 | JWT_SECRET: process.env.JWT_SECRET, 78 | SESSION_TIMEOUT_MS: process.env.SESSION_TIMEOUT_MS || '3600000', 79 | 80 | COOKIE_SECRET: process.env.COOKIE_SECRET, // secret password for cookies 81 | 82 | // re-assign all process.env variables to be used in this app and defined with dotenv to constants 83 | // In this way I can see all variables defined with donenv and used in this app 84 | // In CI I can't use dotenv => I provide default values for all these constants 85 | LARGE_PAYLOAD_MESSAGE: process.env.LARGE_PAYLOAD_MESSAGE, 86 | EXPRESS_SESSION_SECRET: process.env.EXPRESS_SESSION_SECRET, 87 | HELMET_HIDE_POWERED_BY: process.env.HELMET_HIDE_POWERED_BY, 88 | HELMET_REFERRER_POLICY: process.env.HELMET_REFERRER_POLICY, 89 | HELMET_EXPECT_CT_REPORT_URI: process.env.HELMET_EXPECT_CT_REPORT_URI, 90 | 91 | // rate limiter for all APIs 92 | RATELIMITER_WINDOW_MS: process.env.RATELIMITER_WINDOW_MS, 93 | RATELIMITER_MAX: process.env.RATELIMITER_MAX, 94 | RATELIMITER_DELAY_AFTER: process.env.RATELIMITER_DELAY_AFTER, 95 | RATELIMITER_DELAY_MS: process.env.RATELIMITER_DELAY_MS, 96 | RATELIMITER_MESSAGE: process.env.RATELIMITER_MESSAGE 97 | }; 98 | -------------------------------------------------------------------------------- /servers/node-express-js/src/config.js: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2017-2019 Stefano Cappa 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | 'use strict'; 24 | 25 | const path = require('path'); 26 | 27 | const notInCI = process.env.CI !== 'yes' && process.env.CI !== true; 28 | console.log(`Use dotenv condition is: ${notInCI}, because I cannot use dotenv with CI, so I have to skip it`); 29 | 30 | if (notInCI === true) { 31 | console.log('Initializing dotenv (requires .env/.env_prod file)'); 32 | let dotenvName = null; 33 | switch (process.env.NODE_ENV) { 34 | case 'development': 35 | console.log('dotenv read: .env'); 36 | dotenvName = '.env'; 37 | break; 38 | case 'test': 39 | console.log('dotenv read: .env (you are running with NODE_ENV=test)'); 40 | dotenvName = '.env'; 41 | break; 42 | default: 43 | case 'production': 44 | console.log('dotenv read: .env_prod'); 45 | dotenvName = '.env_prod'; 46 | break; 47 | } 48 | 49 | const dotenvAbsolutePath = path.join(__dirname, '../' + dotenvName); 50 | 51 | const dotenv = require('dotenv').config({ 52 | path: dotenvAbsolutePath 53 | }); 54 | if (dotenv.error) { 55 | throw dotenv.error; 56 | } 57 | console.log(`dotenv parsed with NODE_ENV=${process.env.NODE_ENV}`, dotenv.parsed); 58 | } 59 | 60 | // ATTENTION!!! 61 | // don't use here logger.js because it requires config fully initialized 62 | 63 | module.exports = { 64 | isProd: () => process.env.NODE_ENV === 'production', 65 | isTest: () => process.env.NODE_ENV === 'test', 66 | isCI: () => process.env.CI === 'yes' || process.env.CI === true, 67 | 68 | NODE_ENV: process.env.NODE_ENV || 'development', 69 | CI: process.env.CI || 'yes', 70 | 71 | FRONT_END_PATH: process.env.FRONT_END_PATH, 72 | PORT: process.env.PORT || process.env.NODE_ENV === 'production' ? 80 : 3000, 73 | 74 | LOG_FOLDER: process.env.LOG_FOLDER, 75 | 76 | // Jwt config for apis server <-> client 77 | JWT_SECRET: process.env.JWT_SECRET, 78 | SESSION_TIMEOUT_MS: process.env.SESSION_TIMEOUT_MS || '3600000', 79 | 80 | COOKIE_SECRET: process.env.COOKIE_SECRET, // secret password for cookies 81 | 82 | // re-assign all process.env variables to be used in this app and defined with dotenv to constants 83 | // In this way I can see all variables defined with donenv and used in this app 84 | // In CI I can't use dotenv => I provide default values for all these constants 85 | LARGE_PAYLOAD_MESSAGE: process.env.LARGE_PAYLOAD_MESSAGE, 86 | EXPRESS_SESSION_SECRET: process.env.EXPRESS_SESSION_SECRET, 87 | HELMET_HIDE_POWERED_BY: process.env.HELMET_HIDE_POWERED_BY, 88 | HELMET_REFERRER_POLICY: process.env.HELMET_REFERRER_POLICY, 89 | HELMET_EXPECT_CT_REPORT_URI: process.env.HELMET_EXPECT_CT_REPORT_URI, 90 | 91 | // rate limiter for all APIs 92 | RATELIMITER_WINDOW_MS: process.env.RATELIMITER_WINDOW_MS, 93 | RATELIMITER_MAX: process.env.RATELIMITER_MAX, 94 | RATELIMITER_DELAY_AFTER: process.env.RATELIMITER_DELAY_AFTER, 95 | RATELIMITER_DELAY_MS: process.env.RATELIMITER_DELAY_MS, 96 | RATELIMITER_MESSAGE: process.env.RATELIMITER_MESSAGE 97 | }; 98 | --------------------------------------------------------------------------------