by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Johan Vaage
@Jovaage
I have a problem with mongoose.
When I try to return a validation error .send(400, err), to the client. The only thing that is sent through restify is
{
    "message": "User validation failed"
}
Even though the actuall object, err, is a much larger object
Muhammad Saqib
@segmentationfaulter
Does restify works with node version 6.0?
Justin Keller
@nodesocket
@segmentationfaulter I'm using it with Node 6.1. There is a warning being thrown from a depend package though, see issue restify/node-restify#1067
Says due to be fixed in the next release of restify.
whartman-ulabs
@whartman-ulabs

Hey there!
I am relatively new to using restify and had some questions on how to serve static files and not dork up the routes I have for my REST services.

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

This setup here conflicts with my other routes that are now unreachable:

server.get({path : SURVEY_QUESTION_PATH, version : appVersion}, getLandingSurveyQuestions);
How do I serve up static content at my root, but allow my GET routes to be accessible?
Yannick Grenzinger
@ygrenzinger
Hello @whartman-ulabs in my code, I first load the routes of the REST API
then i add this code:
server.get(/.*/, restify.serveStatic({
    directory: './app',
    default: 'index.html'
}));
whartman-ulabs
@whartman-ulabs
One way I have gotten around this is to change the regex pattern:
server.get(/(^\/$)|(\.(html|js|css|png|jpg|jpeg)$)/, restify.serveStatic({
  directory: 'static',
  default: 'index.html'
}));
Yannick Grenzinger
@ygrenzinger
hmmm .... mine seems a little bit simpler
sadly I can't share my code on public repo :(
whartman-ulabs
@whartman-ulabs
I agree
Let me give that a try
Yannick Grenzinger
@ygrenzinger
full code:
const routesToLoad = [
    'filesForRoutes.js',
    '....js'];
routesToLoad.forEach(function (curFile) {
    logger().debug('loading route: ' + curFile);
    const route = require('./routes/' + curFile);
    route.routes(server);
});

server.get(/.*/, restify.serveStatic({
    directory: './app',
    default: 'index-aiguillage.html'
}));
whartman-ulabs
@whartman-ulabs
My static content loads, but not my GET routes with that approach
server.get({path : SURVEY_QUESTION_PATH, version : appVersion}, getLandingSurveyQuestions);

server.get(/.*/, restify.serveStatic({ 
    directory: './static', 
    default: 'index.html' 
}));
Yannick Grenzinger
@ygrenzinger
And if you invert the 2 'get' ?
whartman-ulabs
@whartman-ulabs
Doesn't make a difference.
server.get(/.*/, restify.serveStatic({ 
    directory: './static', 
    default: 'index.html' 
}));

server.get({path : SURVEY_QUESTION_PATH, version : appVersion}, getLandingSurveyQuestions);
Yannick Grenzinger
@ygrenzinger
Then ... I have no ideas :(
sorry
Seems I met the same problem but no idea why it's working for me now and not yours
whartman-ulabs
@whartman-ulabs
NP. I'll stick with my hack for now. Thanks!
bebo
@bebor

hi guys. would somebody would be so kind to answer REST related question?

when i create a resource:
POST /apples {come data}

how should UI then get the id of the newely created resource?

Daniel Colgan
@danielcolgan
Hello everyone! I'm looking for some information about creating NodeJS RESTful API server for mobile apps, maybe somebody knows, posts or tutorials? restify best framework for this? - Thank you!
avimar
@avimar
@DanielMcColgan restify is great for making a REST API. If you needed something more generic, there's express, hapi, etc... but restify focuses on REST.
@bebor the user side can create a UUID to post... which has to be checked for unique-ness, but give it back json with the new ID
Johnie Lee
@JohnieLee
I am using Promise with Restify. Is there a way to set up a catch all for errors? The uncaughtException doesn't work because that only catches errors, but doesn't handle next(err) calls.
Johnie Lee
@JohnieLee
Alternatively, would it be possible to make the exception event emitter work for parent error classes?
avimar
@avimar
@JohnieLee I've just ended up with this pattern:
    .then(function(results) {
        res.json(200,results);
        })
    .catch(function(err) {
        res.json(500, err);
        })
    .finally(next);
you can't even put res inside a .then() I think since it needs access to req,res,next
simply returning the promise would be pretty cool though, could cut most of my boilerplate.
Johnie Lee
@JohnieLee
I started hacking around and I think this pattern works. It's kind of a hack but is consistent with the design of restify
.then(function(result) {
    // do something that throws error
   throw SomeApplicationError()
})
.catch(err) {
  const wrappedError = new WrappedError(err);
  next(err);
}

server.on('Wrapped', function (req, res, err, cb) {
  // Error handler for application error
  // unwrap the error to find actual application error
  cb();
});
The motivation for that is that it is istill compatible with the middleware concept
server.get('/someEndpoint', [paramValidationMiddleware, endpointHandler, postProcessor])
scippio
@scippio
Hi...
Anybody know what is the default request timeout in the Restify client?
scippio
@scippio
Infinity? ... shiiit..
vellotis
@vellotis
you can't override it?
scippio
@scippio
no I can ... :) it's ok :)
thx
vellotis
@vellotis
Actually I reviewed the code a bit more and saw that it is a bit more complex than that. But still no timeout
you should set requestTimeout
avimar
@avimar
so.. restify logs everything to bunyan at info level. I want to try to monitor errors... 404 not found and not auth probably aren't so important, but others might be. Any suggestions? Perhaps save to bunyan based on code of http response?