restify

XLSX File corrupted when sent from Node.js via Restify to Client

故事扮演 提交于 2019-12-10 23:56:48
问题 I am working on a project where I am creating an excel file using XLSX node.js library, sending it to a client via Restify where I then use the FileSaver.js library to save it on the local computer. When I write the xlsx workbook to file on the backend, it opens fine, however, when I open it on the client, it is corrupted. I get the error: "Excel cannot open this file. The file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension

Cannot find module dtrace-provider

核能气质少年 提交于 2019-12-10 02:56:29
问题 I have a simple nodejs application that is throwing "Cannot find module './build/Release/DTraceProviderBindings'" . I look it up online and it looks like that a lot of people are having the same problem when using restify on windows (which is my case, I'm using restify on windows 10). Apparently, dtrace-provider is a optional module for restify and there is no version of it for windows. So, what I tried so far: Update node to v6.2.0; Uninstall all modules and run npm install --no-optional ;

What is the best way to implement a token-based authentication for restify.js?

ぐ巨炮叔叔 提交于 2019-12-09 14:44:04
问题 I'm trying to build a RESTful api with restify.js, but I don't want to expose the api to everyone. And I'm going to use token-based authentication. The process in my mind is like this, I'm not sure whether it is reasonable. the user send username/password to an api to acquire the token. this token should be included in the request for the calls of every other api. If this is reasonable, is there any node.js library I can use? In addition, how do I protect the token? If someone intercept a

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

安稳与你 提交于 2019-12-08 21:23:26
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 above. describe('retrieveAll()', function() { reqStub = {}; resStub = {send: sinon.stub()}; nextStub =

The consequences of not calling next() in restify

邮差的信 提交于 2019-12-08 15:02:44
问题 I've been using Restify for some time now. I ran across some code that lacks next() and it occurred to me that I'm not sure if I fully understand the reason why next() should be called after res.send() . I get why would use it in a middleware situation, but for a normal route why is it needed? For example: server.get('/a/:something/',function(req,res,next) { res.send('ok'); }); vs server.get('/b/:something/',function(req,res,next) { res.send('ok'); return next(); }); If return next(); is left

Node.js react and rest routes in same project

ε祈祈猫儿з 提交于 2019-12-08 03:06:05
问题 I’m quite new to NodeJS and made a few apps that act like a rest service , and I call the rest service from an HTML page . I have also made a few react apps. Question : can I have these 2 types of apps in the same app , so that my react apps can use the local rest URLs. If so , how do I start the app? ( given that there are 2 different command lines to start each type of app. Sorry if this is a stupid question , still getting my head around all these types of projects . Note : I am using

Having issues with integrating passport-local with restify

本秂侑毒 提交于 2019-12-07 19:01:43
问题 My sample application is as follows var util = require("util") restify = require("restify"), q = require("q"), _ = require("lodash"); //Create Server var server = restify.createServer({ name: "TestAuth" }); server.use(restify.queryParser()); server.use(restify.bodyParser()); //Initialize Passport var passport = require("passport"), LocalStrategy = require("passport-local").Strategy; server.use(passport.initialize()); passport.use(new LocalStrategy( function(username, password, done) { return

How to avoid the data of request stream loss after doing some authentication on node.js?

十年热恋 提交于 2019-12-05 15:57:33
How do request streams works with node.js (express or restify) ? When a client who tries to upload an audio, mpeg or other binary file to the server, the request should be a Readable Stream on the server. that we could pipe into another stream using request.pipe() to for example get the file from the request, and then upload the file to amazon s3 using knox. When I'm using an asynchronous authentication method part of the streamed data is being lost and the length doesn't match with the transmitted content-length header anymore. Is there any way to avoid this behavior? Is the data of request

Node.js stream upload directly to Google Cloud Storage

℡╲_俬逩灬. 提交于 2019-12-05 12:12:10
I have a Node.js app running on a Google Compute VM instance that receives file uploads directly from POST requests (not via the browser) and streams the incoming data to Google Cloud Storage (GCS). I'm using Restify b/c I don't need the extra functionality of Express and because it makes it easy to stream the incoming data. I create a random filename for the file, take the incoming req and toss it to a neat little Node wrapper for GCS (found here: https://github.com/bsphere/node-gcs ) which makes a PUT request to GCS. The documentation for GCS using PUT can be found here: https://developers

Using everyauth with restify

僤鯓⒐⒋嵵緔 提交于 2019-12-05 01:09:37
问题 I'm trying to use everyauth to handle authentication for a rest api created with restify. But can't find a starting point. I'd expect to be doing something like: var restify = require('restify'); var everyauth = require('everyauth'); var server = restify.createServer(); server.use(everyauth.middleware()); but restify does not accept the everyauth middleware. How do I go about setting up restify and everyauth? 回答1: The issue you are having is restify does not and current will not have a