Skip to content

Instantly share code, notes, and snippets.

@seanpmaxwell
Last active May 29, 2019 05:35
Show Gist options
  • Save seanpmaxwell/9cd75e5d9c4c3d6da3f028a1e1499632 to your computer and use it in GitHub Desktop.
Save seanpmaxwell/9cd75e5d9c4c3d6da3f028a1e1499632 to your computer and use it in GitHub Desktop.
TypeScriptFullStackShell/src/DemoServer.ts
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