request-promise

Why is my API call not hitting the endpoint? (Typescript, request-promise)

ⅰ亾dé卋堺 提交于 2021-02-11 13:50:47
问题 I can't get my API call to hit the endpoint. I have 2 TypeScript projects, one is a list of API endpoints, and the other is a process that will call a series of API endpoints to perform operations. The API endpoint will take a JSON Web token and process it in header (Swagger documentation has it defined and brought in as the following: "security": [ { "Bearer": [] } ] where "Bearer" is defined at the security protocols at the top: "securityDefinitions": { "Bearer": { "type": "apiKey", "name":

HTTP Auth request fails in browser due to CORS, ok in Node

喜欢而已 提交于 2021-02-09 10:39:00
问题 I'm stuck trying to diagnose a problem where a GET request with HTTP Basic Auth succeeds in Node, but fails in the browser. The problem manifests directly as a CORS failure (there's no Access-Control-Allow-Origin on the 401 page). request.js:119 OPTIONS http://HOST?PARAMS 401 (Unauthorized) ClientRequest._onFinish @ request.js:119 (anonymous) @ request.js:61 ... 17:53:59.170 localhost/:1 Failed to load http://HOST?PARAMS: Response to preflight request doesn't pass access control check: No

HTTP Auth request fails in browser due to CORS, ok in Node

荒凉一梦 提交于 2021-02-09 10:33:52
问题 I'm stuck trying to diagnose a problem where a GET request with HTTP Basic Auth succeeds in Node, but fails in the browser. The problem manifests directly as a CORS failure (there's no Access-Control-Allow-Origin on the 401 page). request.js:119 OPTIONS http://HOST?PARAMS 401 (Unauthorized) ClientRequest._onFinish @ request.js:119 (anonymous) @ request.js:61 ... 17:53:59.170 localhost/:1 Failed to load http://HOST?PARAMS: Response to preflight request doesn't pass access control check: No

node.js send form data to another server

試著忘記壹切 提交于 2021-01-29 14:25:20
问题 I received the file from the front-end no problem but then when I try to send it to another server, I get a "413 Request Entity Too Large" in the best case scenario. Does anyone have an idea what I'm doing wrong? I have also tried with axios... getting the same issue Thanks, Guys index.js app.use((req, res, next) => { res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Methods', 'GET, POST, DELETE, PUT, PATCH, OPTIONS'); res.setHeader('Access-Control-Allow

Nodejs request-promise combining json api data from 2 links?

走远了吗. 提交于 2021-01-29 14:00:08
问题 const express = require('express'); const app = express(); const path = require('path'); const config = require('./config.json'); const moment = require('moment'); const request = require('request-promise'); url = 'https://ne.api.site', url2 = 'https://n2.api.site', app.set('view engine', 'pug'); app.use(express.static(path.join(__dirname, 'public'))); async function getApi(){ return request({ url : url, url2 : url2 }); } /* Routes */ app.get('/', async (req, res) => { let api = await getApi(

How to ignore self signed certificate issue in request-promise

*爱你&永不变心* 提交于 2020-07-09 05:42:10
问题 I am using request-promise module for my node app to make some API call. https://www.npmjs.com/package/request-promise import request from 'request-promise'; let options = { method: GET, json: true, uri : "https://" +this.urls + endpoint, body: payload, rejectUnauthorized: false // This doesn't work }; let response = await request(options) SInce the API what I am trying to use is insecure (having self signed certificate), the conncetion is failing with this error: Error: connect ECONNREFUSED

Best method of moving to a new page with request-promise?

房东的猫 提交于 2020-01-06 14:57:12
问题 I am tinkering around with request-promise to crawl a friends webpage. I am using the crawl a webpage better example on their GitHub. What I have so far is this: var rp = require('request-promise'); var cheerio = require('cheerio'); // Basically jQuery for node.js var options = { uri: 'https://friendspage.org', transform: function(body) { return cheerio.load(body); } }; rp(options) .then(function($) { // Process html like you would with jQuery... var nxtPage = $("a[data-url$='nxtPageId']")

Node.js - Working with an API limit of 5 requests per second

孤人 提交于 2019-12-30 06:55:14
问题 I've got a 'script' that does thousands of requests to a specific API. This API will only allow 5 requests per second (and probably it measures differently then me). To make the requests I'm using request-promise framework, and I've superseded the normal request-promise function with this: const request_promise = require('request-promise') function waitRetryPromise() { var count = 0 // keeps count of requests function rp(options) { const timedCall = (resolve) => setTimeout( ()=>resolve(rp

Why is the Promise reject() in my jest.mock going to a then() rather than a catch()?

梦想的初衷 提交于 2019-12-19 18:28:53
问题 I have two files, getItemInfo.js to make API calls and getItemInfo.test.js which is the respective Jest test file. On the test file, I am mocking the http calling triggered by node module request-promise . The question is on the second code block, surrounded by ********* 's. Basically why is the reject() error still going to a then() block in the second unit test? // getItemInfo.js const rp = require('request-promise'); const getItemInfo = (id) => { const root = 'https://jsonplaceholder

request-promise download pdf file

妖精的绣舞 提交于 2019-12-12 08:15:33
问题 I received multiple pdf files and must download it from a REST-API. After auth and connect I try to download the file with request-promise: const optionsStart = { uri: url, method: 'GET', headers: { 'X-TOKEN': authToken, 'Content-type': 'applcation/pdf' } } request(optionsStart) .then(function(body, data) { let writeStream = fs.createWriteStream(uuid+'_obj.pdf'); console.log(body) writeStream.write(body, 'binary'); writeStream.on('finish', () => { console.log('wrote all data to file'); });