I'm new to Node.js. I'm trying to create a web server that will 1) serve up static html web pages and 2) provide a basic JSON / REST API. I've been told by my management that I must use RESTIFY (I don't know why). Currently, I have the following:
var restify = require('restify');
var fs = require('fs');
var mime = require('mime');
var ecstatic = require('ecstatic');
var ws = restify.createServer({
name: 'site',
version: '0.2.0'
});
ws.use(restify.acceptParser(server.acceptable));
ws.use(restify.queryParser());
ws.use(restify.bodyParser());
ws.use(ecstatic({ root: __dirname + '/' }));
ws.get('/rest/customers', findCustomers);
ws.get('/', ecstatic({ root:__dirname }));
ws.get(/^\/([a-zA-0-9_\.~-]+\/(.*)/, ecstatic({ root:__dirname }));
server.listen(90, function() {
console.log('%s running on %s', server.name, server.url);
});
function findCustomers() {
var customers = [
{ name: 'Felix Jones', gender:'M' },
{ name: 'Sam Wilson', gender:'M' },
{ name: 'Bridget Fonda', gender:'F'}
];
return customers;
}
After I start the web server, and I try to visit http://localhost:90/rest/customers/
in my browser, the request is made. However, it just sits there and I never seem to get a response. I'm using Fiddler to monitor the traffic and the result stays as '-' for a long time.
How can I return some JSON from this type of REST call?
Thank you