"Invalid regular expression: unterminated group" when attempting to set up restify static route

StackOverflow https://stackoverflow.com/questions/21959550

سؤال

I am trying use restify to serve all paths that don't begin with /api from a directory containing static files.

var restify = require('restify');

var server = restify.createServer();                                                                           
server.get(/^\/(?!api)/, restify.serveStatic({                                                                   
    directory: './static'                                                                                        
}));                                                                                                             

server.listen(8080, function() {                                                                                 
    console.log('%s listening at %s', server.name, server.url);                                                
}); 

But, when I attempt going to, say, http://0.0.0.0:8080/index.html, I get:

{"code":"InternalError","message":"Invalid regular expression: /^/(?!a/: Unterminated group"}

I am doubly confused because:

 $ node
> var e = /^\/(?!api)/;
undefined
> e.test('/api/v1');
false
> e.test('/index.html');
true
هل كانت مفيدة؟

المحلول

The static files plugin was broken at the time of this posting. See my debug at https://github.com/mcavage/node-restify/issues/537.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top