Hi,
I have to use app.mountpath in the views of my app, as a prefix for some urls. In this example i used it for the url to a css file which is in a public directory in the app (/app/public), but it could also be used for dynamically creating links depending on the mountpath.
What i did is basically this:
// /index.js
var app = express()
var mountpoint = "/foo";
app.use(mountpoint, require("./app/index.js"))
// /app/index.js
var app = module.exports = express()
app.locals.baseurl = app.mountpath.replace(/\/$/, "") // <-- of course, this is set to '/' at this moment, because it is not yet mounted under 'mountpoint' (/foo)
var router = express.Router()
var route = router.route("/bar")
route.get(function(request, response, next) {
response.render("bar")
});
app.use(router)
// /app/views/bar.jade
doctype html
html(lang="en")
head
meta(charset="utf-8")
link(href="#{baseurl}/css/style.css", rel="stylesheet")
When requesting /foo/bar the link href should be /foo/css/style.css but it is /css/style.css
Maybe i am using it in a way it was not intended. If so, please tell me how i can achieve the same result.
Thanks
cheers
Thomas
Hi,
I have to use
app.mountpathin the views of my app, as a prefix for some urls. In this example i used it for the url to a css file which is in a public directory in the app (/app/public), but it could also be used for dynamically creating links depending on the mountpath.What i did is basically this:
When requesting
/foo/barthe link href should be/foo/css/style.cssbut it is/css/style.cssMaybe i am using it in a way it was not intended. If so, please tell me how i can achieve the same result.
Thanks
cheers
Thomas