Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serving Static content #28

Closed
dtorres opened this issue Jun 30, 2011 · 5 comments
Closed

Serving Static content #28

dtorres opened this issue Jun 30, 2011 · 5 comments

Comments

@dtorres
Copy link
Contributor

dtorres commented Jun 30, 2011

Great work, I've just finished my API but now i want to put a placeholder webpage for the ones who visits the root.

I've managed to send text fine but when i try to serve images or another binaries it crashes...

any idea on how to solve this? or how to bind this to a static server like node-static at the same port as restify?

thanks.

@mcavage
Copy link
Contributor

mcavage commented Jun 30, 2011

Hi,

No this should definitely work (I do it). Here's a gist with a crude "serve up API docs from ./docs" set of routes from one of my projects. Not the most elegant (or error-resistant), but it should get you going: https://gist.github.com/1056404

Anyway, I'll leave this ticket open to fix the docs since you're the second or third person that's asked about this. Also, do you have a stack trace ? (if it's throwing TypeError because you're sending a buffer into res.send() et al, that's what it should do - if it's something else I'll clean it up).

m

@mcavage
Copy link
Contributor

mcavage commented Aug 12, 2011

Closing this out.

@mcavage mcavage closed this as completed Aug 12, 2011
@mullr
Copy link

mullr commented Mar 6, 2012

I case anyone else comes here for the same reason, I had at least initial success with the following (using restify 1.1.1):

var static = require('node-static');

file = new static.Server('./public');
server.get(/^\/.*/, function(req, res, next) {
  file.serve(req, res, next);
});

@tlevine
Copy link

tlevine commented Jan 16, 2013

@mullr's is great; the included static server almost as good, but it doesn't serve the index as I would expect.

@jedahan
Copy link
Contributor

jedahan commented Jan 16, 2013

@tlevine To server up index, I used the built in static server

server.get /\/*/, restify.serveStatic directory: './static'

and then added early on

server.pre (req, res, next) ->
  req.url = '/index.html' if req.url is '/'
  next()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants