2

I'm trying to write restful application using node.js restify. Here is my application's code :

var restify = require('restify');

var server = restify.createServer();

server.get(/.*/, restify.serveStatic({
    directory: 'content',
    default: 'index.html'
 }));

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

So, I can access index.html only by http://localhost:3000/index.html. I also expect to see my index.html page on the root url, http://localhost:3000/ but now i'm receiving there

{"code":"ResourceNotFound","message":"/"}
ftkvyn
  • 106
  • 4
  • should `server.get(/.*/` not be `server.get(/*` or similar ? what's the dot for ? – Rob Sedgwick Apr 26 '14 at 18:18
  • It is regexp that is maching any string. Dot means any symbol, star means that it may be any number of symbols. – ftkvyn Apr 26 '14 at 18:36
  • Ah, nice feature -- does this help http://stackoverflow.com/questions/20399648/restify-why-serving-working-directory-is-not-possible ? - regarding the `directory` - - only other thing I can think of – Rob Sedgwick Apr 26 '14 at 18:53
  • I have tried that - didn't help with my issue. – ftkvyn Apr 26 '14 at 19:14
  • I was able to get your example working - are you sure you have a 'content' directory with a 'index.html' file in it? Good to verify the basics :) – pherris Apr 28 '14 at 21:04
  • Yes, I am, I can even reach it, but as http://localhost:3000/index.html, not as http://localhost:3000/. Did you get index.html on http://localhost:3000/ url? – ftkvyn Apr 29 '14 at 07:31

1 Answers1

4

Give this a try:

server.get(/\//, restify.serveStatic({
    directory: './content',
    default: 'index.html'
 }));
MForMarlon
  • 865
  • 9
  • 24