Files
habitica/website/server/middlewares/static.js
Matteo Pagliazzi 99f50f825a Old Client Cleanup (#9141)
* move emails images to website/static/emails and remove old files

* remove old client tests

* remove more files

* add sprites back

* cleanup gulp

* cleanup gulp

* remove old files

* more fixes

* pin bootstrap-vue

* disable old test

* remove old tasks

* fix apidoc
2017-10-12 16:44:28 +02:00

23 lines
1.0 KiB
JavaScript

import express from 'express';
import nconf from 'nconf';
import path from 'path';
const IS_PROD = nconf.get('IS_PROD');
const MAX_AGE = IS_PROD ? 31536000000 : 0;
const BASE_DIR = path.join(__dirname, '/../../..');
module.exports = function staticMiddleware (expressApp) {
// Expose static files for new client
expressApp.use('/static/js', express.static(`${BASE_DIR}/dist-client/static/js`, { maxAge: MAX_AGE }));
expressApp.use('/static/css', express.static(`${BASE_DIR}/dist-client/static/css`, { maxAge: MAX_AGE }));
expressApp.use('/static/img', express.static(`${BASE_DIR}/dist-client/static/img`, { maxAge: MAX_AGE }));
// @TODO img/js/css under /static have their names hashed after every change so they can be cached
// Not files in /audio and /sprites, that's why we don't cache them.
// Hash their file names and cache the entire /static folder
expressApp.use('/static', express.static(`${BASE_DIR}/dist-client/static`));
// Apidoc
expressApp.use('/apidoc', express.static(`${BASE_DIR}/apidoc_build`));
};