restify

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

谁说胖子不能爱 提交于 2019-12-22 09:15:08
问题 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

Node.js EventEmitter error

戏子无情 提交于 2019-12-20 05:39:15
问题 I have an error when trying to inherit EvenEmitter /* Consumer.js */ var EventEmitter = require('events').EventEmitter; var util = require('util'); var Consumer = function() {}; Consumer.prototype = { // ... functions ... findById: function(id) { this.emit('done', this); } }; util.inherits(Consumer, EventEmitter); module.exports = Consumer; /* index.js */ var consumer = new Consumer(); consumer.on('done', function(result) { console.log(result); }).findById("50ac3d1281abba5454000001"); /*

AngularJS: $http interceptor change every call method to OPTIONS

两盒软妹~` 提交于 2019-12-20 02:57:24
问题 So, I'm trying to intercept the http calls to add the Authorization header on each call if exist. This works well exept of the fact that no matter which http method I use (GET, POST, DELETE) it send the request with OPTIONS method instead. What am I doing wrong? Server is nodejs with restify. angular.module('mymodule').factory('RequestService', function () { var token = null; var service = { setToken: function setToken(_token) { token = _token; }, getToken: function getToken() { return token;

How to do parallel async multiple requests at once with Promises in Node

不想你离开。 提交于 2019-12-19 09:24:04
问题 Array and loops through but I want to be able to run all of them in parallel instead as I don't want to run one after another. I basically want to store all endpoint calls status codes, body and time as array and return them as results regardless of there are errors or not in the endpoint. I'm using Bluebird, how can I use its features to solve this issue? 回答1: You can use Promise.map with .bind : function getComponentStatuses(componentsToCheck) { return Promise.map(componentsToCheck,

RESTify on Node.js POST body / json

北城余情 提交于 2019-12-19 05:29:12
问题 I am in need of help. I am POSTing json data to my node server. The node server is using RESTify for its API. I am having trouble getting req.body.name from the body of the posted data. The posted data contains a json body. In it i have keys such as name, date, address, email, etc. I want to get the name out of the json body. I am trying to do req.body.name but it is not working. I have also included server.use(restify.bodyParser()); and it is not working. I am able to req.params.name and

CORS-enabled server not denying requests

大兔子大兔子 提交于 2019-12-17 21:06:24
问题 I am trying to use express Cors with my resitfy server and it doesn't seem to be denying requests coming from other ips. I am working locally so I tried setting origin to a random public ip but all of my requests are still going through Here is my route: module.exports = function(app) { var user = require('./controllers/userController'); var cors = require('cors'); var corsOptions = require('./cors.json'); app.post('/auth/signup', cors(corsOptions),user.createUser); app.post('/auth/login',

PassportJS redirect loop

爷,独闯天下 提交于 2019-12-13 14:06:32
问题 Below is the code I have restify = require("restify") passport = require("passport") GoogleStrategy = require("passport-google").Strategy jsonContentType = (req, res, next) -> res.setHeader("content-type", "application/json") next(req, res, next) server = restify.createServer( name: "Sparked API" ) passport.use(new GoogleStrategy({ returnURL: "http://localhost:8080/auth/google/return" realm: "http://localhost:8080/" }, (id, profile, done) -> done() )) server.use(jsonContentType) server.get("/

location object expected, location array not in correct format

折月煮酒 提交于 2019-12-12 08:06:51
问题 I have spent doing such a straight forward thing. I just want to do a CRUD operation on a user model using nodejs, mongoose, restify stack. My mongo instance is on mongolab. The user should contain a "loc" field . User schema is as follows : var mongoose = require('mongoose') var Schema = mongoose.Schema; var userSchema = new Schema( { email_id : { type: String, unique: true }, password: { type: String}, first_name: String, last_name: String, age: String, phone_number: String, profile_picture

Restify static webserver stops working after enabling HTTP basic authentication

徘徊边缘 提交于 2019-12-12 06:05:31
问题 I have a working node.js restify server configured to work as a static webserver. Here is the relevant code; var server = restify.createServer({ name: 'myapp', version: '1.0.0' }); var static_webserver = function (app) { app.get(/.*/, restify.serveStatic({ 'directory': 'static', //static html files stored in ../static folder 'default': 'index.html' })); } //var static_server = function (app) static_webserver(server); After I enable HTTP Basic authentication to have better security for the

node.js + restify - requiring client certificate

白昼怎懂夜的黑 提交于 2019-12-12 04:13:25
问题 So I'm working on a basic node app. Clients will connect to it with SSL. It seems to work fine when I just use a server certificate, but when I attempt to require a client certificate, it continues to work no matter what I throw at it. I have found questions on this site related to this, but the answers contained therein didn't seem to work for me. Here's one. Here's relevant code: var restify=require('restify'); var fs=require('fs'); var server=restify.createServer({ certificate: fs