Question

I'm creating a simple testing platform for an app and have the following code setup as my server.js file in the root of my app:

var restify = require('restify'),
    nstatic = require('node-static'),
    fs = require('fs'),
    data = __dirname + '/data.json',
    server = restify.createServer();


// Serve static files
var file = new nstatic.Server('');
server.get(/^\/.*/, function(req, res, next) {
    file.serve(req, res, next);
});


// Process GET
server.get('/api/:id', function(req, res) {
    // NEVER FIRES
});

It serves static files perfectly, however, when I try to make a call to the /api it just hangs and times out. Imagine I'm missing something stupid here, any help would be greatly appreciated.

Was it helpful?

Solution 2

You may make yourself sure the api get call is caught by moving the second get before the first. The reason is your api calls routes are already matched by the first pattern.

OTHER TIPS

node-static is calling next with an error, which means it's never yielding to other handlers.

You can move your other handlers above node-static or ignore it's errors by intercepting it's callback.

I made a working version here: http://runnable.com/UWXHRONG7r1zAADe

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top