├── .gitignore ├── LICENSE ├── README.md ├── package.json ├── src ├── DemoServer.ts ├── controllers │ ├── demo │ │ ├── DemoController.test.ts │ │ └── DemoController.ts │ ├── index.ts │ └── shared │ │ └── TestServer.test.ts ├── public │ └── react │ │ └── demo-react │ │ ├── .gitignore │ │ ├── README.md │ │ ├── package.json │ │ ├── public │ │ ├── favicon.ico │ │ ├── index.html │ │ └── manifest.json │ │ ├── src │ │ ├── App.css │ │ ├── App.test.tsx │ │ ├── App.tsx │ │ ├── index.css │ │ ├── index.tsx │ │ ├── logo.svg │ │ ├── react-app-env.d.ts │ │ └── serviceWorker.ts │ │ └── tsconfig.json └── start.ts ├── tsconfig.json ├── tslint.json └── util ├── buildForProd.sh └── nodemon.json /.gitignore: -------------------------------------------------------------------------------- 1 | # GitIgnore file, prevent files/folders 2 | # from being committed. 3 | # remove all cached files git rm -r --cached . 4 | 5 | 6 | # IntelliJ project files 7 | *.iml 8 | .idea/ 9 | 10 | 11 | # Built/Transpiled files 12 | **/build/ 13 | **/src/**/*.js 14 | **/src/**/*.js.map 15 | 16 | 17 | # Misc 18 | **/node_modules/ 19 | **/package-lock.json -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Sean Maxwell 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TypeScriptFullStackShell 2 | Setting up a web application for full-stack TypeScript development 3 | 4 | ## Commands: 5 | - `npm start`: start the app in production mode. Production code must be built for production first: `npm run build`. 6 | - `npm run start-dev`: start the Express server in dev mode. Will activate TypeScript file-watcher 7 | and generate source-maps. 8 | - `npm run build` at _root/_ will build the app for production. Contents are output to _build/_. 9 | - `npm test`: Run back-end unit-tests. If you want to run a specific unit test run `npm run test -- "path to the unit-test file"`, 10 | i.e. `npm test -- controllers/demo/DemoController`. 11 | Because source-map files are generated for map files too, debugging in IDEs should still work. 12 | 13 | ## Links 14 | OvernightJS 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "typescriptfullstackshell", 3 | "version": "1.0.0", 4 | "description": "demonstrate how to do full-stack TypeScript development", 5 | "main": "src/start.js", 6 | "scripts": { 7 | "start": "npm install --only=prod && NODE_ENV=production node ./build/start.js", 8 | "start-dev": "nodemon --config \"./util/nodemon.json\"/", 9 | "test": "NODE_ENV=testing ts-node ./src/start.ts", 10 | "build": "sh ./util/buildForProd.sh" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/seanpmaxwell/TypeScriptFullStackShell.git" 15 | }, 16 | "keywords": [ 17 | "TypeScript", 18 | "Express", 19 | "React", 20 | "FullStack", 21 | "Professional", 22 | "Enterprise", 23 | "Startup" 24 | ], 25 | "author": "Sean Maxwell", 26 | "license": "MIT", 27 | "bugs": { 28 | "url": "https://github.com/seanpmaxwell/TypeScriptFullStackShell/issues" 29 | }, 30 | "homepage": "https://github.com/seanpmaxwell/TypeScriptFullStackShell#readme", 31 | "dependencies": { 32 | "@overnightjs/core": "^1.6.4", 33 | "@overnightjs/logger": "^1.1.4", 34 | "express": "^4.16.4", 35 | "http-status-codes": "^1.3.2" 36 | }, 37 | "devDependencies": { 38 | "@types/body-parser": "^1.17.0", 39 | "@types/express": "^4.16.0", 40 | "@types/jasmine": "^3.3.7", 41 | "@types/node": "^10.12.18", 42 | "@types/supertest": "^2.0.7", 43 | "jasmine": "^3.3.1", 44 | "nodemon": "^1.18.10", 45 | "supertest": "^3.4.1", 46 | "ts-node": "^8.0.2", 47 | "tsc": "^1.20150623.0", 48 | "tslint": "^5.12.1", 49 | "tslint-lines-between-class-members": "^1.3.1", 50 | "typescript": "^3.2.4" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/DemoServer.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Express Server file. 3 | * 4 | * created by Sean Maxwell Jan 21, 2019 5 | */ 6 | 7 | import * as path from 'path'; 8 | import * as express from 'express'; 9 | import * as bodyParser from 'body-parser'; 10 | import * as controllers from './controllers'; 11 | 12 | import { Server } from '@overnightjs/core'; 13 | import { Logger } from '@overnightjs/logger'; 14 | 15 | 16 | class DemoServer extends Server { 17 | 18 | private readonly SERVER_START_MSG = 'Demo server started on port: '; 19 | private readonly DEV_MSG = 'Express Server is running in development mode. No front-end ' + 20 | 'content is being served.'; 21 | 22 | 23 | constructor() { 24 | super(true); 25 | this.app.use(bodyParser.json()); 26 | this.app.use(bodyParser.urlencoded({extended: true})); 27 | this.setupControllers(); 28 | // Point to front-end code 29 | if (process.env.NODE_ENV !== 'production') { 30 | this.app.get('*', (req, res) => res.send(this.DEV_MSG)); 31 | } else { 32 | this.serveFrontEndProd(); 33 | } 34 | } 35 | 36 | 37 | private setupControllers(): void { 38 | const ctlrInstances = []; 39 | for (const name in controllers) { 40 | if (controllers.hasOwnProperty(name)) { 41 | let Controller = (controllers as any)[name]; 42 | ctlrInstances.push(new Controller()); 43 | } 44 | } 45 | super.addControllers(ctlrInstances); 46 | } 47 | 48 | 49 | private serveFrontEndProd(): void { 50 | const dir = path.join(__dirname, 'public/react/demo-react/'); 51 | // Set the static and views directory 52 | this.app.set('views', dir); 53 | this.app.use(express.static(dir)); 54 | // Serve front-end content 55 | this.app.get('*', (req, res) => { 56 | res.sendFile('index.html', {root: dir}); 57 | }); 58 | } 59 | 60 | 61 | public start(port: number): void { 62 | this.app.listen(port, () => { 63 | Logger.Imp(this.SERVER_START_MSG + port); 64 | }); 65 | } 66 | } 67 | 68 | export default DemoServer; 69 | -------------------------------------------------------------------------------- /src/controllers/demo/DemoController.test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Unit-tests for the DemoController 3 | * 4 | * created by Sean Maxwell, 1/21/2019 5 | */ 6 | 7 | import * as supertest from 'supertest'; 8 | 9 | import {} from 'jasmine'; 10 | import { OK, BAD_REQUEST } from 'http-status-codes'; 11 | import { SuperTest, Test } from 'supertest'; 12 | import { Logger } from '@overnightjs/logger'; 13 | 14 | import TestServer from '../shared/TestServer.test'; 15 | import DemoController from './DemoController'; 16 | 17 | 18 | describe('DemoController', () => { 19 | 20 | const demoController = new DemoController(); 21 | let agent: SuperTest; 22 | 23 | 24 | beforeAll(done => { 25 | const server = new TestServer(); 26 | server.setController(demoController); 27 | agent = supertest.agent(server.getExpressInstance()); 28 | done(); 29 | }); 30 | 31 | 32 | describe('API: "/api/say-hello/:name"', () => { 33 | 34 | const { SUCCESS_MSG } = DemoController; 35 | const name = 'seanmaxwell'; 36 | const message = SUCCESS_MSG + name; 37 | 38 | it(`should return a JSON object with the message "${message}" and a status code 39 | of "${OK}" if message was successful`, done => { 40 | 41 | agent.get('/api/say-hello/' + name) 42 | .end((err, res) => { 43 | if (err) { 44 | Logger.Err(err, true); 45 | } 46 | expect(res.status).toBe(OK); 47 | expect(res.body.message).toBe(message); 48 | done(); 49 | }); 50 | }); 51 | 52 | it(`should return a JSON object with the "error" param and a status code of "${BAD_REQUEST}" 53 | if message was unsuccessful`, done => { 54 | 55 | agent.get('/api/say-hello/make_it_fail') 56 | .end((err, res) => { 57 | if (err) { 58 | Logger.Err(err, true); 59 | } 60 | expect(res.status).toBe(BAD_REQUEST); 61 | expect(res.body.error).toBeTruthy(); 62 | done(); 63 | }); 64 | }); 65 | }); 66 | }); 67 | -------------------------------------------------------------------------------- /src/controllers/demo/DemoController.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Demo Controller file. 3 | * 4 | * created by Sean Maxwell Jan 21, 2019 5 | */ 6 | 7 | import { OK, BAD_REQUEST } from 'http-status-codes'; 8 | import { Controller, Get } from '@overnightjs/core'; 9 | import { Logger } from '@overnightjs/logger'; 10 | import { Request, Response } from 'express'; 11 | 12 | 13 | @Controller('api/say-hello') 14 | class DemoController { 15 | 16 | public static readonly SUCCESS_MSG = 'hello '; 17 | 18 | 19 | @Get(':name') 20 | private sayHello(req: Request, res: Response) { 21 | try { 22 | const { name } = req.params; 23 | if (name === 'make_it_fail') { 24 | throw Error('User triggered failure'); 25 | } 26 | Logger.Info(DemoController.SUCCESS_MSG + name); 27 | return res.status(OK).json({ 28 | message: DemoController.SUCCESS_MSG + name, 29 | }); 30 | } catch (err) { 31 | Logger.Err(err, true); 32 | return res.status(BAD_REQUEST).json({ 33 | error: err.message, 34 | }); 35 | } 36 | } 37 | } 38 | 39 | export default DemoController; 40 | -------------------------------------------------------------------------------- /src/controllers/index.ts: -------------------------------------------------------------------------------- 1 | export * from './demo/DemoController'; 2 | -------------------------------------------------------------------------------- /src/controllers/shared/TestServer.test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * JobApp ExpressJS webserver 3 | * 4 | * created by Sean Maxwell Jan 19, 2019 5 | */ 6 | 7 | import * as bodyParser from 'body-parser'; 8 | import { Application } from 'express'; 9 | import { Server } from '@overnightjs/core'; 10 | 11 | 12 | class TestServer extends Server { 13 | 14 | 15 | constructor() { 16 | super(); 17 | this.app.use(bodyParser.json()); 18 | this.app.use(bodyParser.urlencoded({extended: true})); 19 | } 20 | 21 | 22 | public setController(ctlr: object): void { 23 | super.addControllers(ctlr); 24 | } 25 | 26 | 27 | public getExpressInstance(): Application { 28 | return this.app; 29 | } 30 | } 31 | 32 | export default TestServer; 33 | -------------------------------------------------------------------------------- /src/public/react/demo-react/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /src/public/react/demo-react/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `npm start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `npm test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `npm run build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `npm run eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | -------------------------------------------------------------------------------- /src/public/react/demo-react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo-react", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@types/jest": "23.3.13", 7 | "@types/node": "10.12.18", 8 | "@types/react": "16.7.20", 9 | "@types/react-dom": "16.0.11", 10 | "react": "^16.7.0", 11 | "react-dom": "^16.7.0", 12 | "react-scripts": "2.1.3", 13 | "typescript": "3.2.4" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test", 19 | "eject": "react-scripts eject" 20 | }, 21 | "proxy": "http://localhost:3001", 22 | "eslintConfig": { 23 | "extends": "react-app" 24 | }, 25 | "browserslist": [ 26 | ">0.2%", 27 | "not dead", 28 | "not ie <= 11", 29 | "not op_mini all" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /src/public/react/demo-react/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seanpmaxwell/TypeScriptFullStackShell/e4f058d8ecb19c0a1411b68a0700a7b53e5d9861/src/public/react/demo-react/public/favicon.ico -------------------------------------------------------------------------------- /src/public/react/demo-react/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 15 | 16 | 25 | React App 26 | 27 | 28 | 29 |
30 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/public/react/demo-react/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /src/public/react/demo-react/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | animation: App-logo-spin infinite 20s linear; 7 | height: 40vmin; 8 | } 9 | 10 | .App-header { 11 | background-color: #282c34; 12 | min-height: 100vh; 13 | display: flex; 14 | flex-direction: column; 15 | align-items: center; 16 | justify-content: center; 17 | font-size: calc(10px + 2vmin); 18 | color: white; 19 | } 20 | 21 | .App-link { 22 | color: #61dafb; 23 | } 24 | 25 | @keyframes App-logo-spin { 26 | from { 27 | transform: rotate(0deg); 28 | } 29 | to { 30 | transform: rotate(360deg); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/public/react/demo-react/src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /src/public/react/demo-react/src/App.tsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import logo from './logo.svg'; 3 | import './App.css'; 4 | 5 | class App extends Component { 6 | 7 | render() { 8 | 9 | async function callExpress() { 10 | try { 11 | let response = await fetch('/api/say-hello/SeanMaxwell') 12 | .then(res => res.json()); 13 | alert('Hi this is a response from the backend: ' + response.response); 14 | } catch (err) { 15 | alert(err); 16 | } 17 | } 18 | 19 | callExpress(); 20 | 21 | return ( 22 |
23 |
24 | logo 25 |

26 | Edit src/App.tsx and save to reload. 27 |

28 | 34 | Learn React 35 | 36 |
37 |
38 | ); 39 | } 40 | 41 | } 42 | 43 | export default App; 44 | -------------------------------------------------------------------------------- /src/public/react/demo-react/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 5 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 6 | sans-serif; 7 | -webkit-font-smoothing: antialiased; 8 | -moz-osx-font-smoothing: grayscale; 9 | } 10 | 11 | code { 12 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 13 | monospace; 14 | } 15 | -------------------------------------------------------------------------------- /src/public/react/demo-react/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import * as serviceWorker from './serviceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | 9 | // If you want your app to work offline and load faster, you can change 10 | // unregister() to register() below. Note this comes with some pitfalls. 11 | // Learn more about service workers: http://bit.ly/CRA-PWA 12 | serviceWorker.unregister(); 13 | -------------------------------------------------------------------------------- /src/public/react/demo-react/src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/public/react/demo-react/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /src/public/react/demo-react/src/serviceWorker.ts: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read http://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.1/8 is considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | type Config = { 24 | onSuccess?: (registration: ServiceWorkerRegistration) => void; 25 | onUpdate?: (registration: ServiceWorkerRegistration) => void; 26 | }; 27 | 28 | export function register(config?: Config) { 29 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 30 | // The URL constructor is available in all browsers that support SW. 31 | const publicUrl = new URL( 32 | (process as { env: { [key: string]: string } }).env.PUBLIC_URL, 33 | window.location.href 34 | ); 35 | if (publicUrl.origin !== window.location.origin) { 36 | // Our service worker won't work if PUBLIC_URL is on a different origin 37 | // from what our page is served on. This might happen if a CDN is used to 38 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 39 | return; 40 | } 41 | 42 | window.addEventListener('load', () => { 43 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 44 | 45 | if (isLocalhost) { 46 | // This is running on localhost. Let's check if a service worker still exists or not. 47 | checkValidServiceWorker(swUrl, config); 48 | 49 | // Add some additional logging to localhost, pointing developers to the 50 | // service worker/PWA documentation. 51 | navigator.serviceWorker.ready.then(() => { 52 | console.log( 53 | 'This web app is being served cache-first by a service ' + 54 | 'worker. To learn more, visit http://bit.ly/CRA-PWA' 55 | ); 56 | }); 57 | } else { 58 | // Is not localhost. Just register service worker 59 | registerValidSW(swUrl, config); 60 | } 61 | }); 62 | } 63 | } 64 | 65 | function registerValidSW(swUrl: string, config?: Config) { 66 | navigator.serviceWorker 67 | .register(swUrl) 68 | .then(registration => { 69 | registration.onupdatefound = () => { 70 | const installingWorker = registration.installing; 71 | if (installingWorker == null) { 72 | return; 73 | } 74 | installingWorker.onstatechange = () => { 75 | if (installingWorker.state === 'installed') { 76 | if (navigator.serviceWorker.controller) { 77 | // At this point, the updated precached content has been fetched, 78 | // but the previous service worker will still serve the older 79 | // content until all client tabs are closed. 80 | console.log( 81 | 'New content is available and will be used when all ' + 82 | 'tabs for this page are closed. See http://bit.ly/CRA-PWA.' 83 | ); 84 | 85 | // Execute callback 86 | if (config && config.onUpdate) { 87 | config.onUpdate(registration); 88 | } 89 | } else { 90 | // At this point, everything has been precached. 91 | // It's the perfect time to display a 92 | // "Content is cached for offline use." message. 93 | console.log('Content is cached for offline use.'); 94 | 95 | // Execute callback 96 | if (config && config.onSuccess) { 97 | config.onSuccess(registration); 98 | } 99 | } 100 | } 101 | }; 102 | }; 103 | }) 104 | .catch(error => { 105 | console.error('Error during service worker registration:', error); 106 | }); 107 | } 108 | 109 | function checkValidServiceWorker(swUrl: string, config?: Config) { 110 | // Check if the service worker can be found. If it can't reload the page. 111 | fetch(swUrl) 112 | .then(response => { 113 | // Ensure service worker exists, and that we really are getting a JS file. 114 | const contentType = response.headers.get('content-type'); 115 | if ( 116 | response.status === 404 || 117 | (contentType != null && contentType.indexOf('javascript') === -1) 118 | ) { 119 | // No service worker found. Probably a different app. Reload the page. 120 | navigator.serviceWorker.ready.then(registration => { 121 | registration.unregister().then(() => { 122 | window.location.reload(); 123 | }); 124 | }); 125 | } else { 126 | // Service worker found. Proceed as normal. 127 | registerValidSW(swUrl, config); 128 | } 129 | }) 130 | .catch(() => { 131 | console.log( 132 | 'No internet connection found. App is running in offline mode.' 133 | ); 134 | }); 135 | } 136 | 137 | export function unregister() { 138 | if ('serviceWorker' in navigator) { 139 | navigator.serviceWorker.ready.then(registration => { 140 | registration.unregister(); 141 | }); 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/public/react/demo-react/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "module": "esnext", 16 | "moduleResolution": "node", 17 | "resolveJsonModule": true, 18 | "isolatedModules": true, 19 | "noEmit": true, 20 | "jsx": "preserve" 21 | }, 22 | "include": [ 23 | "src" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /src/start.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Start the server for development or production, 3 | * or run tests. 4 | * 5 | * created by Sean Maxwell, 1/21/2019 6 | */ 7 | 8 | import { Logger } from '@overnightjs/logger'; 9 | import DemoServer from './DemoServer'; 10 | 11 | // Start the server or run tests 12 | if (process.env.NODE_ENV !== 'testing') { 13 | 14 | let server = new DemoServer(); 15 | server.start(process.env.NODE_ENV === 'development' ? 3001 : 8081); 16 | 17 | } else { 18 | 19 | const Jasmine = require('jasmine'); 20 | const jasmine = new Jasmine(); 21 | 22 | jasmine.loadConfig({ 23 | "spec_dir": "src", 24 | "spec_files": [ 25 | "./controllers/**/*.test.ts" 26 | ], 27 | "stopSpecOnExpectationFailure": false, 28 | "random": true 29 | }); 30 | 31 | jasmine.onComplete((passed: boolean) => { 32 | if (passed) { 33 | Logger.Info('All tests have passed :)'); 34 | } else { 35 | Logger.Err('At least one test has failed :('); 36 | } 37 | }); 38 | 39 | let testPath = process.argv[3]; 40 | 41 | if (testPath) { 42 | testPath = `./src/${testPath}.test.ts`; 43 | jasmine.execute([testPath]); 44 | } else { 45 | jasmine.execute(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "module": "commonjs", 5 | "strict": true, 6 | "baseUrl": "./", 7 | "outDir": "build", 8 | "sourceMap": true, 9 | "removeComments": true, 10 | "experimentalDecorators": true, 11 | "target": "es6", 12 | "emitDecoratorMetadata": true, 13 | "moduleResolution": "node", 14 | "importHelpers": true, 15 | "types": [ 16 | "node" 17 | ], 18 | "typeRoots": [ 19 | "node_modules/@types" 20 | ] 21 | }, 22 | "include": [ 23 | "./src/**/*.ts" 24 | ], 25 | "exclude": [ 26 | "./src/**/*.test.ts", 27 | "./src/public/" 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "lines-between-class-members": [true, 2], 5 | "max-line-length": { 6 | "options": [100] 7 | }, 8 | "member-ordering": false, 9 | "no-consecutive-blank-lines": false, 10 | "object-literal-sort-keys": false, 11 | "ordered-imports": false, 12 | "quotemark": [true, "single"], 13 | "variable-name": [true, "allow-leading-underscore"] 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /util/buildForProd.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | 4 | 5 | ### Bundle BackEnd ### 6 | 7 | # Remove existing production folder 8 | rm -rf ./build/ 9 | 10 | # Transpile .ts to .js 11 | tsc --sourceMap false 12 | 13 | 14 | 15 | ### Bundle FrontEnd ### 16 | 17 | # Create the directory for React 18 | mkdir -p ./build/public/react/ 19 | 20 | # Navigate to the react directory 21 | cd ./src/public/react/demo-react 22 | 23 | # Build React code 24 | npm run build 25 | 26 | # Rename the folder 27 | mv build demo-react 28 | 29 | # Move the contains to the build/ dir 30 | mv demo-react ../../../../build/public/react/ 31 | -------------------------------------------------------------------------------- /util/nodemon.json: -------------------------------------------------------------------------------- 1 | { 2 | "watch": ["src"], 3 | "ext": "ts", 4 | "ignore": ["src/public"], 5 | "exec": "NODE_ENV=development ts-node src/start.ts" 6 | } 7 | --------------------------------------------------------------------------------