Skip to content

Instantly share code, notes, and snippets.

@lopezjurip
Last active June 30, 2017 16:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lopezjurip/4e54213f0231b73ff551fced61bd9a02 to your computer and use it in GitHub Desktop.
Save lopezjurip/4e54213f0231b73ff551fced61bd9a02 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