node.js - res.sendfile() doesn't serve javascripts well -


i want use static file serve without rendering engine. i've tried use:

res.sendfile('public/index.html'); 

on '/' route, , express middleware static files on route:

app.use(express.static(path.join(__dirname, 'public'))); 

but seems of javascripts client asks downloaded index.html file information.

how can make successful download of css/js static files ?

update:

here route "res.sendfile ..." :

app.get('/*', index); 

i want of requests server on route index.html , of js&css assosiciated with.

i guess might you...

in app.js file...

app.use(app.router); app.use(express.static(path.join(__dirname, 'public')));  app.use("/styles",  express.static(__dirname + '/public/stylesheets')); app.use("/scripts", express.static(__dirname + '/public/javascripts')); app.use("/images",  express.static(__dirname + '/public/images'));   // development if ('development' == app.get('env')) {   app.use(express.errorhandler()); }  app.get('/', function (req, res) {       res.sendfile(__dirname + '/public/home.html'); }); 

save home.html inside /public folder , javascript files in /public/javascripts, images in /public/images, css files in /public/stylesheets folder.

in html file reference should words define(eg: /scripts/home.js)... this

    <link rel="stylesheet"   type="text/css" href="/styles/home.css" >     <script src="/scripts/home.js" type="text/javascript"></script>    

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -