jdx / mean-sample

Sample project for Write Modern Web Apps with the MEAN Stack by Jeff Dickey
https://mean-sample.herokuapp.com
166 stars 90 forks source link

Chapter 6 - app.css and app.js not found, result in 404 #16

Closed bmontgom closed 9 years ago

bmontgom commented 9 years ago

Everything is building, gulp is outputting the app.css and app.js files into the /assets directory. This directory by the way is an immediate child of the main application directory. It would look like localhost:3000/assets

Anyways, they are not able to be referenced by posts.html. If I move the app.css and app.js files into the /ng directory, everything works! Clearly this is not supposed to be happening though, and I cannot find any differences between your code and mine. I've gone over your code here in the repo and double checked that I was typing everything in correctly whilst reading the chapter.

Below is my project structure.

project structure

This is what happens in chrome:

image

Any help would be appreciated

jdx commented 9 years ago

what does your server.js look like?

bmontgom commented 9 years ago

Well there are two, so I'll post both of them.

The one in the scripts folder:

var gulp = require( "gulp" );
var nodemon = require( "gulp-nodemon" );

gulp.task( "dev:server", function ()
{
    nodemon(
        {
            script: "server.js",
            ext: "js",
            ignore: [ "ng*", "gulp*", "assets*" ]
        }
    );
} );

The actual node server file:

var express = require( "express" );
var bodyParser = require( 'body-parser' );
var app = express();

app.use( bodyParser.json() );
app.use( "/api/posts", require( "./controllers/api/posts.js" ) );
app.use( require( "./controllers/static.js" ) );

app.listen( 3000, function ()
{
    console.log( 'Server listening on', 3000 );
} );
jdx commented 9 years ago

ah what's in controllers/static.js?

bmontgom commented 9 years ago

var express = require("express"); var router = express.Router();

router.get( "/", function ( req, res ) { var path = require("path"); res.sendFile( path.resolve() + "/views/posts.html" ); } );

router.use(express.static(__dirname + "/../ng"));

module.exports = router;

jdx commented 9 years ago

you only have the ng folder added, you need to add the assets one as well

bmontgom commented 9 years ago

Ok would that be done by adding

router.use( express.static( __dirname + "/../assets" ) ); ?

jdx commented 9 years ago

right

bmontgom commented 9 years ago

Ok thanks for the help. Was I just supposed to infer that this line would need to be included? I don't remember seeing anything about it in the chapter. Unfortunately I haven't been able to talk to any of my fellow students about this, so it's just been my own two eyes rereading the chapter; I'm sure I easily could have missed it.

jdx commented 9 years ago

I'm fairly certain it's mentioned. Chiefly because I haven't heard of any issues with this yet, but if someone else chimes in on here with a similar problem I'll make sure.

BillLucky commented 7 years ago

Look this : Not loading and 404 for javascript files #104