2017-07-04 2 views
-3

Ich habe lange versucht, die CSS-Datei zu laden. Ich habe mir andere Stackoverflow-Fragen angeschaut und kein Glück. Ich habe die ausdrücklichen Aussagen. Ich habe die "Standard" -Dateireihenfolge. Es scheint, dass ich etwas sehr sehr offensichtlich falsch mache.CSS 404 Node.JS

<html> 
    <head> 
     <link rel="stylesheet" href="style.css"> 
    </head> 
    <body> 
     <nav> 
      <ul> 
       <li class="inline"><a class="inline" target="_blank" href="http://instagram.com/blakskyben/?hl=en">My Insta</a></li> 
       <li class="inline"><a class="inline" href="/about">About Me</a></li> 
       <li class="inline"><a class="inline" href="/">Blogs</a></li> 
      </ul> 
     </nav> 
___________________________________________________________________________ 
    var express = require("express"), 
     app = express(), 
     bodyParser = require("body-parser"), 
     mongoose = require("mongoose"); 

    mongoose.connect("mongodb://localhost/blog"); 

    var blogSchema = new mongoose.Schema({ 
     title: String, 
     content: String 
    }); 

    app.use(express.static("public")); 
    app.use(express.static("partials")); 

    app.use(bodyParser.urlencoded({extended: false})); 
    app.use(bodyParser.json()); 

    app.get("/",function(req,res){ 
     res.redirect("/blogs"); 
    }); 

    app.get("/blogs",function(req,res){ 
     blog.find({},function(err,foundBlogs){ 
      if(foundBlogs){ 
       res.render("blogs.ejs",{blogs: foundBlogs}); 
      } else { 
       res.send("Sorry, an error occured retriving the blogs, " + err); 
      } 
     }); 
    }); 

    app.get("/blogs/:id",function(req,res){ 
     blog.findById(req.params.id,function(err,foundBlog){ 
      if(foundBlog){ 
       res.render("show.ejs",{blog: foundBlog}); 
      } else { 
       res.send("Sorry, but there was an error, " + err); 
      } 
     }); 
    }); 

    app.get("/about",function(req,res){ 
     res.render("about.ejs"); 
    }); 

    var blog = mongoose.model("blog",blogSchema); 

    //Seed the DB! 

    blog.create({ 
     title: "Camp", 
     content: "Blah." 
    }); 

    app.listen(8080); 
+0

Ist 'style.css' in Ihrem Projektverzeichnis? – Chip

+0

Es befindet sich im CSS-Ordner im Öffentlichen Ordner. –

Antwort

0

Versuchen Sie, die CSS-Pfad aus der Anwendung der Wurzel direcotry d.h

<link rel="stylesheet" href="/style.css"> 

oder wenn Ihre CSS-Datei hinzufügen ist in einem Ordner, dann

<link rel="stylesheet" href="/folderName/style.css"> 

je nachdem, was für Sie anwendbar.

+0

Nein. Keiner von denen hat funktioniert. –

0

Ich glaube, der Pfad zu Ihren statischen Verzeichnissen ist falsch. Statt

app.use(express.static("public")); 

versuchen

app.use(express.static(__dirname + "/public")); 
Verwandte Themen