"Invalid regex: unterminated group" when trying to configure a static static route

I am trying to use restify to serve all paths that do not start with /apifrom 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 try to go, let's 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
+3
source share
1 answer

The static file plugin was broken during this post. See my debugging answer at https://github.com/mcavage/node-restify/issues/537 .

+3
source

All Articles