Skip to content

Instantly share code, notes, and snippets.

@sethbergman
Forked from lopezjurip/app.js
Created June 30, 2017 16:04
Show Gist options
  • Save sethbergman/92d0727822f0a903811e6307209cbac1 to your computer and use it in GitHub Desktop.
Save sethbergman/92d0727822f0a903811e6307209cbac1 to your computer and use it in GitHub Desktop.
// server/app.js
const express = require('express');
const morgan = require('morgan');
const path = require('path');
const app = express();
// Setup logger
app.use(morgan(':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] :response-time ms'));
// Serve static assets
app.use(express.static(path.resolve(__dirname, '..', 'build')));
// Always return the main index.html, so react-router render the route in the client
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, '..', 'build', 'index.html'));
});
module.exports = app;
// server/index.js
'use strict';
const app = require('./app');
const PORT = process.env.PORT || 9000;
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}!`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment