It looks like you have html5 mode on in angular, but aren't handling the 
redirects server side properly?

On Friday, March 20, 2015 at 7:44:15 PM UTC-7, John Lim wrote:
>
> hey guys i don't know why am i getting this kind of problem, and i can't 
> seem to find any related issue on stackoverflow or from google. what i'm 
> trying to do is to get some data from database and display it however i 
> always getting master.html file as return, master.html is where all the 
> js,css library located. i'm using angular-ui router for my app some of them 
> have pointed out that if html5mode true will return master.html file if the 
> configuration have error however, i'm using html5mode and everything seem 
> fine i'm still getting partial view html file. so here's my code 
>
> *this is my file structure *
>
>
> <https://lh3.googleusercontent.com/-oGHLH2yAy_Y/VQzWLmEMHhI/AAAAAAAAAvg/QyqWwRGoQ4c/s1600/Selection_011.png>
> *this is my node.js app.js*
>
> var express = require('express'),
>      app = express(),
>    morgan = require('morgan'),
>    compress = require('compression'),
>    errorHandler = require('errorhandler'),
>    bodyParser = require('body-parser'),
>    favicon = require('static-favicon'),
>    http = require('http'),
>    path = require('path'),
>    routes = require('./routes'),
>    config = require('./config'),
>    moment = require('moment'),
>    qs = require('querystring'),
>    async = require('async'),
>    mongoose = require('mongoose'),
>    request = require('request');
>    
>     "use strict";
> // all environments
> app.use(compress());
> app.use(require('prerender-node'));
> app.set('port', process.env.PORT || 3000);
> app.use(morgan('dev'));
> app.use(bodyParser.json());
> app.use(bodyParser.urlencoded({ extended: true }));
> app.use('/static', express.static(path.join(__dirname, '/public')));
> app.use(favicon());
> app.use(errorHandler());
> app.enable('trust proxy');
> //for html5 mode 
> app.get('*',function(req, res){
>   res.sendFile('master.html', { root: path.join(__dirname, 
> '/public/views/') });
> });
> mongoose.connect(config.MONGO_URI);
> mongoose.connection.on('error', function() {
>   console.error('MongoDB Connection Error. Please make sure that MongoDB 
> is running.');
> });
> routes(app, mongoose);
> http.createServer(app).listen(app.get('port'),function(){
>   console.log('Express server listening on port ' + app.get('port'));
> });
>
>
>  *this is my /routes/index.js file*
> var UserHandler = require('./user');
> module.exports = exports = function(app, db) {
> var userHandler = new UserHandler(db);
> /*
>
>  |--------------------------------------------------------------------------
>  | Login Required Middleware
>
>  |--------------------------------------------------------------------------
>  */
> function ensureAuthenticated(req, res, next) {
>   if (!req.headers.authorization) {
>     return res.status(401).send({ message: 'Please make sure your request 
> has an Authorization header' });
>   }
>   var token = req.headers.authorization.split(' ')[1];
>   var payload = jwt.decode(token, config.TOKEN_SECRET);
>   if (payload.exp <= moment().unix()) {
>     return res.status(401).send({ message: 'Token has expired' });
>   }
>   req.user = payload.sub;
>   next();
> }
>
>
> app.get('/api/me', ensureAuthenticated, userHandler.getMe); //register the 
> route 
>
> }
>
>
> as you can see i have registered the route on my server side and call the 
> function by using userHandler and the getme() function, the function is 
> located in *./users.js* 
> var bcrypt = require('bcryptjs'),
>     jwt = require('jwt-simple'),
>     config = require('../config');
> function UserHandler (db) {
>     "use strict";
>
>     var userSchema = new db.Schema({
>       email: { type: String, unique: true, lowercase: true },
>       password: { type: String, select: false },
>       displayName: String
>     });
>
>   
>     var User = db.model('User', userSchema);
>
>     this.getMe = function(req, res, next){
>           User.findById(req.user, function(err, user) {
>             res.send(user);
>          });
>     }
>
> }
> module.exports = UserHandler;
>  
> *here is my controller.js for angularjs*
> angular.module('clairvy').controller('MasterCtrl', [
>   '$http',
>   '$scope',
>   'Account',
>   function ($http,$scope,Account) {
>     
>   $scope.getProfile = function() {
>       Account.getProfile()
>         .success(function(data) {
>           $scope.user = data;
>           console.log(data)
>         })
>         .error(function(error) {
>           alert("something is wrong when retriving your data");
>         });
>     };
>     $scope.getProfile();
>   }
> ]);
> when i console.log(data) it printed out master.html like this 
>
>
> <https://lh6.googleusercontent.com/-EOvMrxxuqmA/VQzamegITsI/AAAAAAAAAvs/3-dSG2bytw8/s1600/Selection_009.png>
>
> *in my factory.js file *
> clairvy.factory('Account', function($http) {
>     return {
>       getProfile: function() {
>         return $http.get('/api/me');
>       }
>     };
>   });
>  
> i have tried other route like ('api/meee') it still return status 200 but 
> the route is not even registered i am supposed to get 400 right ? 
>
> can anyone help me with this ? i really have no clue how to debug this 
> kind of issue can anyone please enlighten me or point me to the correct 
> direction, your help is appreciated thank you ! 
>
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to