server.js 915 B

12345678910111213141516171819202122232425262728
  1. const path = require('path')
  2. const express = require('express')
  3. const fallback = require('express-history-api-fallback')
  4. // Connectors
  5. const clientAddons = require('./connectors/client-addons')
  6. const plugins = require('./connectors/plugins')
  7. const distPath = path.resolve(__dirname, '../dist')
  8. const publicPath = path.resolve(__dirname, '../ui-public')
  9. const CACHE_CONTROL = 'no-store, no-cache, must-revalidate, private'
  10. module.exports = app => {
  11. app.use(express.static(distPath, { setHeaders }))
  12. app.use('/public', express.static(publicPath, { setHeaders }))
  13. app.use('/_plugin/:id/*', plugins.serve)
  14. app.use('/_plugin-logo/:id', plugins.serveLogo)
  15. app.use('/_addon/:id/*', clientAddons.serve)
  16. app.use(fallback(path.join(distPath, 'index.html'), {
  17. headers: {
  18. 'Cache-Control': CACHE_CONTROL
  19. }
  20. }))
  21. }
  22. function setHeaders (res, path, stat) {
  23. res.set('Cache-Control', CACHE_CONTROL)
  24. }