Serving static files with restify

From the documentation: server.get(/\/docs\/public\/?.*/, restify.plugins.serveStatic({ directory: ‘./public’ })); But this will search files in the ./public/docs/public/ directory. If you want to not append request path to it, use appendRequestPath: false option. I prefer to use __dirname key here: server.get(/\/public\/?.*/, restify.plugins.serveStatic({ directory: __dirname })); The value of __dirname is equal to script file directory path, which … Read more

How can I support cors when using restify

You have to set the server up to set cross origin headers. Not sure if there is a built in use function or not, so I wrote my own. server.use( function crossOrigin(req,res,next){ res.header(“Access-Control-Allow-Origin”, “*”); res.header(“Access-Control-Allow-Headers”, “X-Requested-With”); return next(); } ); I found this from this tutorial. http://backbonetutorials.com/nodejs-restify-mongodb-mongoose/

Error: getaddrinfo ENOTFOUND in nodejs for get call

getaddrinfo ENOTFOUND means client was not able to connect to given address. Please try specifying host without http: var optionsget = { host : ‘localhost’, port : 3010, path : ‘/quote/random’, // the rest of the url with parameters if needed method : ‘GET’ // do GET }; Regarding learning resources, you won’t go wrong … Read more

Why should I use Restify?

Corrigendum: this information is now wrong, keep scrolling! there was an issue with the script causing the Restify test to be conducted on an unintended route. This caused the connection to be kept alive causing improved performance due to reduced overhead. This is 2015 and I think the situation has changed a lot since. Raygun.io … Read more

mongoError: Topology was destroyed

It seems to mean your node server’s connection to your MongoDB instance was interrupted while it was trying to write to it. Take a look at the Mongo source code that generates that error Mongos.prototype.insert = function(ns, ops, options, callback) { if(typeof options == ‘function’) callback = options, options = {}; if(this.s.state == DESTROYED) return … Read more

tech