node.js

How to check the response from global fetch in JEST test case

自闭症网瘾萝莉.ら 提交于 2021-02-10 14:18:43
问题 So, i am using jest for testing my node function which is calling fetch() APi to get the data, now when I am writing the test cases for the same i am getting an error like : expect(received).resolves.toEqual() Matcher error: received value must be a promise Received has type: function Received has value: [Function mockConstructor] my function : export function dataHandler (req, res, next) { const url= "someURL" if (url ) { return fetch(url ) .then((response) => response.json()) .then(

how to get ip address inside cors Dynamic Origin?

谁说我不能喝 提交于 2021-02-10 14:17:46
问题 I build restAPI with nodejs and I want to limit user access with whitelisted ip or domain, to do that I use NPM's CORS package, but I cant get client ip address that access restAPI, so.. how to get the ip address? here the code: const whitelist = ['http://localhost', 'http://127.0.0.1'] const corsOptions = { origin: function (origin, callback) { console.log(whitelist.indexOf(origin)) console.log(origin) // if (whitelist.indexOf(origin) !== -1) { if (whitelist.indexOf('127.0.0.1') !== -1 ||

Music functionality without the correct package discord.js

爱⌒轻易说出口 提交于 2021-02-10 14:16:32
问题 I started making a Discord Bot without thinking I would like to add music/voice functionality. I would now like to add this, but as the docs state you need to install: Without voice support: npm install discord.js With voice support (@discordjs/opus): npm install discord.js @discordjs/opus With voice support (opusscript): npm install discord.js opusscript I installed the one without voice support when I began, can I just install the voice support ones over or will that mess it up. If so, what

Can't play mp4 video in Safari served by nodejs server

耗尽温柔 提交于 2021-02-10 14:16:27
问题 I'm having a problem loading mp4 video files on Safari being served from my nodejs server. The problem does not exist on Chrome. To illustrate the problem, I have a simple html webpage which reads an mp4 file mov_bbb.mp4 served from w3schools. I then download the same file and serve it from my nodejs server. vid1 (served from w3schools) loads fine on both Chrome and Safari. vid2 (served from my nodejs server) load fine on Chrome but not on Safari. Here's a screenshot of what I see in Chrome:

ReferenceError: window is not defined Angular Universal

自古美人都是妖i 提交于 2021-02-10 14:14:38
问题 I'm using Angular 10 and trying to implement SSR in my project. When I run the npm run serve:ssr I'm getting the below error ReferenceError: window is not defined When I googled, they suggested to add domino So below is my server.ts .... const scripts = fs.readFileSync('dist/asfc-web/browser/index.html').toString(); const window = domino.createWindow(scripts); global['window'] = window; global['document'] = window.document; .... still getting the same error, Please guide me how to resolve

ReferenceError: window is not defined Angular Universal

扶醉桌前 提交于 2021-02-10 14:14:35
问题 I'm using Angular 10 and trying to implement SSR in my project. When I run the npm run serve:ssr I'm getting the below error ReferenceError: window is not defined When I googled, they suggested to add domino So below is my server.ts .... const scripts = fs.readFileSync('dist/asfc-web/browser/index.html').toString(); const window = domino.createWindow(scripts); global['window'] = window; global['document'] = window.document; .... still getting the same error, Please guide me how to resolve

Req.body is empty node.js and express

柔情痞子 提交于 2021-02-10 14:14:12
问题 I am trying to send a string from a client side page to a server, but the server receives an empty object. Here is my client side code: fetch("/sugestions/sugestions.txt", { method: "POST", body: JSON.stringify({ info: "Some data" }), headers: { "Content-Type": "application/json; charset=utf-8" } }) .then(res => { if (res.ok) console.log("Yay it worked!"); else window.alert("Uh oh. Something went wrong!\n" + res); }); This is my server side code: const express = require("express"); const url

ReferenceError: window is not defined Angular Universal

浪子不回头ぞ 提交于 2021-02-10 14:11:03
问题 I'm using Angular 10 and trying to implement SSR in my project. When I run the npm run serve:ssr I'm getting the below error ReferenceError: window is not defined When I googled, they suggested to add domino So below is my server.ts .... const scripts = fs.readFileSync('dist/asfc-web/browser/index.html').toString(); const window = domino.createWindow(scripts); global['window'] = window; global['document'] = window.document; .... still getting the same error, Please guide me how to resolve

How to select all child div with same class using Puppeteer?

时间秒杀一切 提交于 2021-02-10 13:58:08
问题 I'm new for Puppeteer and I'm trying to get textContent from two divs that using same class. <div class="post-item"> <div class="post-item-info"> <span class="post-item-status post-comment"></span> 3 </div> <div class="post-item-info"> <span class="post-item-status post-vote"></span> 5 </div> </div> The result that I'm expecting is return an array [3,5]. My current code is below. let postInfo = element.querySelector('.post-item-info'); The problem is it is only return the first one. Please

How to select all child div with same class using Puppeteer?

别说谁变了你拦得住时间么 提交于 2021-02-10 13:57:30
问题 I'm new for Puppeteer and I'm trying to get textContent from two divs that using same class. <div class="post-item"> <div class="post-item-info"> <span class="post-item-status post-comment"></span> 3 </div> <div class="post-item-info"> <span class="post-item-status post-vote"></span> 5 </div> </div> The result that I'm expecting is return an array [3,5]. My current code is below. let postInfo = element.querySelector('.post-item-info'); The problem is it is only return the first one. Please