Closed bmontgom closed 9 years ago
what does your server.js
look like?
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 );
} );
ah what's in controllers/static.js
?
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;
you only have the ng folder added, you need to add the assets one as well
Ok would that be done by adding
router.use( express.static( __dirname + "/../assets" ) ); ?
right
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.
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.
Look this : Not loading and 404 for javascript files #104
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.
This is what happens in chrome:
Any help would be appreciated