Last active
May 29, 2019 05:35
-
-
Save seanpmaxwell/9cd75e5d9c4c3d6da3f028a1e1499632 to your computer and use it in GitHub Desktop.
TypeScriptFullStackShell/src/DemoServer.ts
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(); | |
} | |
} | |
... | |
private serveFrontEndProd(): void { | |
const dir = path.join(__dirname, 'public/react/demo-react/'); | |
// Set the static and views directory | |
this.app.set('views', dir); | |
this.app.use(express.static(dir)); | |
// Serve front-end content | |
this.app.get('*', (req, res) => { | |
res.sendFile('index.html', {root: dir}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment