From a6753d9f448899e78ad8a221adf1a99f42c7ed74 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Sat, 30 Sep 2017 11:48:28 +0200 Subject: [PATCH] Enabling static files somewhere else --- controllers/total/templates/total.pug | 2 +- settings/config.js | 2 ++ templates/base.pug | 8 ++++---- utils/create-url.js | 8 ++++++++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/controllers/total/templates/total.pug b/controllers/total/templates/total.pug index 3e8068c..ca09e90 100644 --- a/controllers/total/templates/total.pug +++ b/controllers/total/templates/total.pug @@ -43,4 +43,4 @@ block extracss } block extrajs - script(src="/static/js/totalTable.js") + script(src=getStatic('js/totalTable.js')) diff --git a/settings/config.js b/settings/config.js index 522cbc5..61eb240 100644 --- a/settings/config.js +++ b/settings/config.js @@ -13,6 +13,8 @@ module.exports.PORT = 4000; module.exports.ADE_BASE_URL = "https://edt.inp-toulouse.fr/jsp/custom/modules/plannings/anonymous_cal.jsp?" +module.exports.STATIC_URL = '/static/'; + const privateConf = require('./private.js'); for (let key in privateConf) { diff --git a/templates/base.pug b/templates/base.pug index 4e723ff..6f3e1e3 100644 --- a/templates/base.pug +++ b/templates/base.pug @@ -4,7 +4,7 @@ html meta(charset='utf-8') meta(name='viewport', content='width=device-width, initial-scale=1, shrink-to-fit=no') block css - link(rel='stylesheet', href='/static/bootstrap/css/bootstrap.min.css') + link(rel='stylesheet', href=getStatic('bootstrap/css/bootstrap.min.css')) style. .navbar .btn { margin-right: 10px; @@ -47,8 +47,8 @@ html .container block content - script(src='/static/bootstrap/js/jquery.min.js') - script(src='/static/bootstrap/js/popper.min.js') - script(src='/static/bootstrap/js/bootstrap.min.js') + script(src=getStatic('bootstrap/js/jquery.min.js')) + script(src=getStatic('bootstrap/js/popper.min.js')) + script(src=getStatic('bootstrap/js/bootstrap.min.js')) block extrajs diff --git a/utils/create-url.js b/utils/create-url.js index 08dc75f..55487d3 100644 --- a/utils/create-url.js +++ b/utils/create-url.js @@ -1,3 +1,5 @@ +const config = require('settings/config'); + let urls = {}; class Url { @@ -13,12 +15,18 @@ function getUrl(name) { return urls[name].url; } +function getStatic(name) { + return config.STATIC_URL + name +} + module.exports = function(req, res, next) { res.locals.getUrl = getUrl; + res.locals.getStatic = getStatic; return next(); } module.exports.getUrl = getUrl; +module.exports.getStatic = getStatic; module.exports.url = function(url, viewName, urlName, method) { let ret = new Url(url, viewName, urlName, method);