angularjs - GET error MEAN App -
i've been learning how use mean stack in order build web apps , far it's been lot of fun. instead of using yeoman generators or npm app generate code me, i've been building whole app ground up. way know how each piece connects , going on app. starting connect front , end of app when looked @ developer console , saw
get http://blog.dev/bower_components/angular/angular.js
not angular, every other resource have (modernizr, angular-routes, mootools, restangular, etc ...). when use yeoman angular generator suppose run grunt serve
command start angular side. because built app scratch , using npm build tool didn't know how build front end server. so, went simple nginx virtual host pointing index.html. here's config:
server { listen 80; server_name blog.dev; root /home/michael/workspace/blog/app; index index.html index.htm; location / { try_files $uri $uri/ =404; } }
i'm not sure other variables affecting situation, if missed please tell me , i'll happy give need!
if you're using mean stack, should able host both end , serve front end directly node.
i'm not sure of project structure here's structure 1 i'm working on now.
/bin --contains file called www.js (used launch app) /data /models /node_modules /public -- contains angular implementation /routes -- contains express routes /temp /upload /views app.js -- main configuration express api.js -- apis package.json
in /bin/www.js file have code start node server.
var app = require('../app'); app.set('port', process.env.port || 3000); var server = app.listen(app.get('port'), function() { debug('express server listening on port ' + server.address().port); });
you'll need setup express , routes @ routes first in routes directory have file called index.js
in file, define 1 route leads angular index.html page.
var express = require('express'); var router = express.router(); /* home page. */ router.get('/', function(req, res) { res.redirect('/pages/index.html'); }); module.exports = router;
and of course you'll need set express.
process.env.tmpdir = 'tmp'; // avoid exdev rename error, see http://stackoverflow.com/q/21071303/76173 var express = require('express'); var path = require('path'); var favicon = require('static-favicon'); var logger = require('morgan'); var cookieparser = require('cookie-parser'); var bodyparser = require('body-parser'); var multer = require('multer'); var flow = require('./flow-node.js')('tmp'); var multipart = require('connect-multiparty'); var multipartmiddleware = multipart(); var uuid = require('uuid'); var mongoose = require('mongoose'); var session = require('express-session'); var routes = require('./routes/index'); var app = express(); app.use(favicon()); app.use(logger('dev')); app.use(bodyparser.json()); app.use(bodyparser.urlencoded()); app.use(cookieparser()); app.use(session({genid: function(req) { return uuid.v4()}, secret: 'xxxxxxxxxxx', saveuninitialized: true, resave: true})); app.use(express.static(path.join(__dirname, 'public'))); app.use('/', routes); app.use('/users', users); module.exports = app;
now assuming have angular files , javascript in 'public' directory somewhere, should able start node following command.
node bin/www
and point browser @ http://localhost:3000 , in business.
hope helps , happy learning.
Comments
Post a Comment