app.js 599 B

1234567891011121314151617181920
  1. // server/app.js
  2. const express = require('express');
  3. const morgan = require('morgan');
  4. const path = require('path');
  5. const app = express();
  6. // Setup logger
  7. app.use(morgan(':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] :response-time ms'));
  8. // Serve static assets
  9. app.use(express.static(path.resolve(__dirname, '..', 'dist')));
  10. // Always return the main index.html, so react-router render the route in the client
  11. app.get('*', (req, res) => {
  12. res.sendFile(path.resolve(__dirname, '..', 'dist', 'index.html'));
  13. });
  14. module.exports = app;