samedi 28 mars 2015

How can I handle angular-route with pure Node.js?

I'm learning Node.js without Express.js (trying to learn Node.js itself). For the server side, I got this:


Node.js



// Creating server
var server = http.createServer(function(request, response) {
var filePath = false;

// Send files for each reqeust
if(request.url == '/') {
filePath = 'public/index.html';
}
else {
filePath = 'public' + request.url;
}

var absPath = './' + filePath;
sendFile(response, cache, absPath); // Send response here
});


And for the client side, I used Angular route (not ui-route).


Angular.js:



app.config(function($routeProvider, $locationProvider) {
$routeProvider.when('/', {
templateUrl: '/partials/foo.html', controller: 'fooCtrl'
});

$routeProvider.when('/bar', {
templateUrl: '/partials/bar.html'
});

$routeProvider.otherwise({redirectTo: '/'});

$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
});


How can I handle angular-route requests with pure Node.js? If I use Express.js, it can be done very easily - but I just want to learn Node.js first.


Aucun commentaire:

Enregistrer un commentaire