I have an AngularJS
project which has two views; /settings
and /
. The app.js
file looks like;
.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: './views/bill.html',
controller: 'BillCtrl'
})
.when('/settings', {
templateUrl: './views/settings.html',
controller: 'SettingsCtrl'
})
.otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode(true);
}]);
Where all the routes are defined.
Then I have app/views/bill.html
& app/views/settings.html
.
Now, grunt serve
works perfectly where I can go to any view using ngHref
. The problem is when I do grunt build
and have nginx
pointed to the build directory (the path is /kds
), I see a GET http://localhost/views/settings.html 404 (Not Found)
The path should be relative, and hence, it should be a GET http://localhost/kds/views/settings.html
but that's not the case. What's going on here?
This looks more like a bad server configuration than anything else. Or is the build messing things up for me?
The server directive is;
location /kds {
alias /Users/asheshambasta/code/kds/dist/;
index index.html index.htm;
}
EDIT (full app.js
)
'use strict';
angular.module('kdsApp', [
'ngCookies',
'ngResource',
'ngSanitize',
'ngRoute',
'apiService',
'Lib',
'ngTouch',
'ipCookie'
])
.run(['$location', 'ipCookie', 'APICfg', function($location, ipCookie, APICfg) {
var login = ipCookie('lgInf');
if (!login || !login.usr || !login.pass || !login.srv) {
$location.path('/settings');
} else {
APICfg.setSrv(login.srv);
APICfg.setCId(login.cId);
}
}])
.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: '/views/bill.html',
controller: 'BillCtrl'
})
.when('/settings', {
templateUrl: '/views/settings.html',
controller: 'SettingsCtrl'
})
.otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode(true);
}]);
All the files needed by the application:
<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/apiservice.js"></script>
<script src="scripts/lib.js"></script>
<script src="scripts/class/bill.js"></script>
<script src="scripts/class/item.js"></script>
<script src="scripts/class/course.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/controllers/bill.js"></script>
<script src="scripts/controllers/settings.js"></script>
<!-- endbuild -->