frontController.js 1.3 KB

1234567891011121314151617181920212223242526
  1. var path = require('path');
  2. var express = require('express');
  3. var FrontController = function(app) {
  4. 'use strict';
  5. var cacheDuration = 365 * 24 * 60 * 60 * 1000; // One year
  6. var assetsPath = (app.get('env') === 'development') ? '../../../front/src' : '../../../front/build';
  7. var routes = ['/', '/about', '/result/:runId', '/result/:runId/timeline', '/result/:runId/rule/:policy', '/queue/:runId'];
  8. routes.forEach(function(route) {
  9. app.get(route, function(req, res) {
  10. res.setHeader('Cache-Control', 'public, max-age=20');
  11. res.sendFile(path.join(__dirname, assetsPath, 'main.html'));
  12. });
  13. });
  14. app.use('/css', express.static(path.join(__dirname, assetsPath, 'css'), { maxAge: cacheDuration }));
  15. app.use('/fonts', express.static(path.join(__dirname, assetsPath, 'fonts'), { maxAge: cacheDuration }));
  16. app.use('/img', express.static(path.join(__dirname, assetsPath, 'img'), { maxAge: cacheDuration }));
  17. app.use('/js', express.static(path.join(__dirname, assetsPath, 'js'), { maxAge: cacheDuration }));
  18. app.use('/views', express.static(path.join(__dirname, assetsPath, 'views'), { maxAge: cacheDuration }));
  19. app.use('/bower_components', express.static(path.join(__dirname, '../../../bower_components'), { maxAge: cacheDuration }));
  20. };
  21. module.exports = FrontController;