1

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.

4

2 に答える 2

3

node-static は next をエラーで呼び出しています。これは、他のハンドラーに決して譲らないことを意味します。

他のハンドラを node-static の上に移動するか、コールバックをインターセプトしてエラーを無視することができます。

ここで作業バージョンを作成しました:http://runnable.com/UWXHRONG7r1zAADe

于 2013-04-10T20:19:22.487 に答える
2

get1 番目の前に2 番目を移動することで、API の get 呼び出しが確実にキャッチされるようにすることができます。その理由は、API 呼び出しルートが最初のパターンで既に一致しているためです。

于 2013-04-10T20:14:30.233 に答える