everyone.
I wanna let front-end js, css files send to client.
So I try to use RegExp to solve it.
Unfortunately, this will make all js (include back-end js) can be browsed by client.
May I focus one folder to send to client @@?
-> config.js
app.get(/(.*)\.(css|js)/i, function (req, res) {
res.sendfile(__dirname + "/" + req.params[0] + "." + req.params[1], function (err) {
if (err)
res.send(404);
});
});
-> views/ jade in this folder
link(rel='stylesheet', href='../stylesheet/bootstrap-3.2.0-dist/css/bootstrap.min.css')
link(rel='stylesheet', href='../stylesheet/bootstrap-3.2.0-dist/examples/carousel/carousel.css')
link(rel='stylesheet', href='../stylesheet/style.css')
.
.
.
script(src='../stylesheet/jquery-1.11.1/jquery-1.11.1.min.js')
script(src='../stylesheet/bootstrap-3.2.0-dist/js/bootstrap.min.js')
Move your client-side code into a public
directory and use the static
middleware.
app.use(express.static(path.join(__dirname, 'public')));