restify

Get restify REST API server to support both HTTPS and HTTP

左心房为你撑大大i 提交于 2020-06-10 04:22:32
问题 I am using node.js restify ver4.0.3 The simple following code works as a simple REST API server that supports HTTP. An example API call is http://127.0.0.1:9898/echo/message var restify = require('restify'); var server = restify.createServer({ name: 'myapp', version: '1.0.0' }); server.use(restify.acceptParser(server.acceptable)); server.use(restify.queryParser()); server.use(restify.bodyParser()); //http://127.0.0.1:9898/echo/sdasd server.get('/echo/:name', function (req, res, next) { res

Post jQuery JSON Object to NodeJs Restify

半城伤御伤魂 提交于 2020-02-01 04:58:05
问题 I want to know why it is so hard to post a simple JSON string in a /:parameter to restify. I have followed many examples but have not found anything concrete. I have the following code in the front end. $("#btnDoTest").click(function() { var jData = { hello: "world" }; var request = $.ajax({ url: "http://localhost:8081/j/", async: false, type: "POST", data: JSON.stringify(jData), contentType: "application/javascript", dataType: "json" }); request.success(function(result) { console.log(result)

restify 2.6.1 how to disable body parser for specific request

巧了我就是萌 提交于 2020-01-01 03:25:30
问题 I am pretty new to node.js services and I am facing a problem with multipart/form-data content type. I need a way to disable body parser functionality for specific request. I am using restify 2.6.1. Below are some snippet of the configuration. My setup is: App.js : server.use(restify.authorizationParser()); server.use(restify.dateParser()); server.use(restify.queryParser()); server.use(restify.jsonp()); server.use(restify.bodyParser()); server.use(restifyValidator); server.use(restify

restify regular expression on named parameter

て烟熏妆下的殇ゞ 提交于 2019-12-25 14:21:57
问题 I am using the restify 2.8.4. Understood that named parameter with regular expression is not supported in Mixing regex and :params in route #247 Instead of cobble both logics into one block. server.get ('/user/:id', function (req, res, next) { var id = req.params.id; // check with isNaN() // if string do this // if number do that } I prefer below code structure: //hit this route when named param is a number server.get (/user\/:id(\\d+)/, function (req, res, next) { var id = req.params.id; //

restify: why serving working directory is not possible?

我怕爱的太早我们不能终老 提交于 2019-12-25 02:39:22
问题 I have a restify server with node.js I use to make some development and tests and to do so, I use serveStatic. I wonder why I cannot use the following configuration without getting 403 errors: server.get(/.*/, restify.serveStatic({ directory: '.', default: "index.html" })); Although if I make a link to my current dir: ln -s . serverDir This will work: server.get(/.*/, restify.serveStatic({ directory: './serverDir', default: "index.html" })); What is the reason for this ? Security ? Bug ?

Calling 'next()' from promises in a middleware causes 'next shouldn't be called more than once'

末鹿安然 提交于 2019-12-24 08:47:25
问题 Recently I changed my code from Express to Restify. I'm honestly not sure if it used to happen before, but I guess it did. Basically in my middleware I call a promisified method and when it resolves I call next and do other stuff in the next middleware. When it is rejected I also want to call next with no errors in some cases. Otherwise it must call the error middleware passing err to next . somePromise() .then(()=>{ next(); }) .catch((err)=>{ if(err.someatt) next(); else next(err) }); It

Error: invalid_request Missing required parameter: scope (Restify & Passportjs w/ Google OAuth2)

廉价感情. 提交于 2019-12-24 00:46:08
问题 So, I've run into a problem with my Node.js app, using Restify and Passportjs (Google OAuth2 strategy). When I use passport.authenticate() , it gives me the following error: 400. That’s an error. Error: invalid_request Missing required parameter: scope I found another question about the same thing from a couple of years ago (invalid_request with missing: scope using Google Passportjs on Google Oauth2). The author said he finally fixed it himself but didn't post the fix. Has anyone else run

Node.js + restify cant upload file

六眼飞鱼酱① 提交于 2019-12-23 20:15:50
问题 Im having problems uploading files to a node.js application using restify. This is my upload code https://gist.github.com/maumercado/7ab5cbbfd27c6b825044 Apparently the events are not being triggered, but I dont really know the reason, also the files are being created, but once I see the size info it says 0 bytes. also this is the server.js file https://gist.github.com/maumercado/ecf948b4b8fc7d39e69e Im using a post request in order to upload the file and node 0.10.7. What can be wrong with

How to upload file using restify

我怕爱的太早我们不能终老 提交于 2019-12-23 12:45:45
问题 I'm trying to upload image file to Rest server(Confluence to be more specific) using Restify module but getting Assertion error. I'm not sure if I'm using right approach for file upload to REST server. Could anyone point me to the right direction? This is my attempt - var restify = require('restify'); var header = {'Authorization': 'Basic xxxxx', 'content-type': 'multipart/form-data'}; var client = restify.createJsonClient({ url: 'http://www.testsite.com', version: '*', headers: header });

Testing Restify Route Handler that contains Promise Code Block, using SinonJs and Mocha

我的未来我决定 提交于 2019-12-23 00:48:08
问题 I have a restify action code block below: function retriveAll(req, res, next) { db.user .find({where: {id: 1}) .then(function(user){ res.send(user); }) .catch(function(details){ res.send(details.message); }) .finally(function(){ next(); }); } I want to test this action specifically validating that res.send() was called within this code block . And later on validating the res.send() returned data. I'm using SinonJs and Mocha for testing framework. Here's a sample test code block for the method