javascriptnode.jsrestifynode-static

NodeJS using node-static and restify together


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.


Solution

  • 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.