This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "typescriptfullstackshell", | |
"version": "1.0.0", | |
"description": "demonstrate how to do full-stack TypeScript development", | |
"main": "build/demo.bundle.js", | |
"scripts": { | |
"start": "npm install --only=prod && NODE_ENV=production node ./build/start.js", | |
"start-dev": "nodemon --config \"./util/nodemon.json\"", | |
"test": "ts-node src/start.ts test", | |
"build": "sh ./util/buildForProd.sh" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (process.argv[2] === 'dev') { | |
process.env.NODE_ENV = 'development'; | |
require('./src/DemoServer'); | |
} else if (process.argv[2] === 'prod') { | |
process.env.NODE_ENV = 'production'; | |
require('./build/demo.bundle'); | |
} else if (process.argv[2] === 'test') { | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constructor() { | |
super(true); | |
this.app.use(bodyParser.json()); | |
this.app.use(bodyParser.urlencoded({extended: true})); | |
this.setupControllers(); | |
// Point to front-end code | |
if (process.env.NODE_ENV !== 'production') { | |
this.app.get('*', (req, res) => res.send(this.DEV_MSG)); | |
} else { | |
this.serveFrontEndProd(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
### Build BackEnd ### | |
# Remove existing production folder | |
rm -rf ./build/ | |
# Transpile .ts to .js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as supertest from 'supertest'; | |
import {} from 'jasmine'; | |
import { OK, BAD_REQUEST } from 'http-status-codes'; | |
import { SuperTest, Test } from 'supertest'; | |
import { Logger } from '@overnightjs/logger'; | |
import TestServer from '../shared/TestServer.test'; | |
import DemoController from './DemoController'; | |
describe('DemoController', () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as bodyParser from 'body-parser'; | |
import { Application } from 'express'; | |
import { Server } from '@overnightjs/core'; | |
class TestServer extends Server { | |
constructor() { | |
super(); | |
this.app.use(bodyParser.json()); | |
this.app.use(bodyParser.urlencoded({extended: true})); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "demo-react", | |
"version": "0.1.0", | |
"private": true, | |
"dependencies": { | |
"@types/jest": "23.3.13", | |
"@types/node": "10.12.18", | |
"@types/react": "16.7.20", | |
"@types/react-dom": "16.0.11", | |
"react": "^16.7.0", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
class App extends Component { | |
render() { | |
async function callExpress() { | |
try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as path from 'path'; | |
import * as express from 'express'; | |
import * as bodyParser from 'body-parser'; | |
import * as controllers from './controllers'; | |
import { Server } from '@overnightjs/core'; | |
import { Logger } from '@overnightjs/logger'; | |
class DemoServer extends Server { | |
private readonly SERVER_START_MSG = 'Demo server started on port: '; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { OK, BAD_REQUEST } from 'http-status-codes'; | |
import { Controller, Get } from '@overnightjs/core'; | |
import { Logger } from '@overnightjs/logger'; | |
import { Request, Response } from 'express'; | |
@Controller('api/say-hello') | |
class DemoController { | |
public static readonly SUCCESS_MSG = 'hello '; |