html - node.js script fails to GET static files -


i have basic html index.html handful of containers, , add bootstrap , font awesome folders <head> section of file. such as:

<link href="../bootstrap/css/bootstrap.css" rel="stylesheet"> <link href="../bootstrap/css/bootstrap-responsive.css" rel="stylesheet"> <link href="font-awesome/css/font-awesome.css" rel="stylesheet"> 

then, wrote web.js script first initialize server , add folders containing static files, in way:

var express = require('express'); var app = express(); var fs = require('fs');  var buf = fs.readfilesync("index.html"); app.use(express.logger());  app.get('/', function(request, response) {   response.send(buf.tostring()); });  app.configure(function(){     app.use(express.static(__dirname + '/assets'));     app.use(express.static(__dirname + '/bootstrap'));     app.use(express.static(__dirname + '/font-awesome')); });  var port = process.env.port || 8080; app.listen(port, function() {   console.log("listening on " + port); }); 

however when go http://localhost:8080 404 errors commands trying obtain bootstrap.css, etc. help? tried different scripts obtained stackoverflow can't seem right. thanks!

by initializing express.static in way, telling in folders off of root requested files.

if remove paths:

<link href="css/bootstrap.css" rel="stylesheet"> <link href="css/bootstrap-responsive.css" rel="stylesheet"> <link href="css/font-awesome.css" rel="stylesheet"> 

your static assets found. however, asking headaches down road duplicate filenames result in first being returned.

instead, might want place of static assets under single directory or add different path parameter app.use statements keep things better organized.

file layout:

public  |-- bootstrap  |-- font-awesome 

corresponding app.use statement (and remove .. html paths):

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

or multiple static middleware (and remove .. html paths):

app.use('/bootstrap', express.static(path.join(__dirname, '/bootstrap'))); app.use('/font-awesome', express.static(path.join(__dirname, '/font-awesome'))); 

html changes either of above:

<link href="bootstrap/css/bootstrap.css" rel="stylesheet"> <link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet"> <link href="font-awesome/css/font-awesome.css" rel="stylesheet"> 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -