express

npm cors package not working

橙三吉。 提交于 2020-01-15 11:05:28
问题 I'm having trouble accessing my server even with the npm cors package installed. import Express from 'express'; import compression from 'compression'; import bodyParser from 'body-parser'; import mongoose from 'mongoose'; import cors from 'cors'; /********************** SERVER CONFIG *********************/ import serverConfig from './config'; import auth from './routes/v1/auth.routes' // Initialize Express const app = new Express(); // DB Setup mongoose.connect(serverConfig.mongoUrl, error =>

Nested queries with pg-promises

扶醉桌前 提交于 2020-01-15 10:14:47
问题 I need to make a query with pg-promise using the result to make 3 others queries but i am getting this error when executing: Unhandled rejection TypeError: Method 'batch' requires an array of values. at batch (C:\apps\pfc\node_modules\spex\lib\ext\batch.js:61:26) at C:\apps\pfc\node_modules\spex\lib\ext\batch.js:149:26 at Task.batch (C:\apps\pfc\node_modules\pg-promise\lib\task.js:120:39).............. This is my code: db.task(t => { return t.one('select gid, idgrupo from orden where gid = $1

How to get child process to write to an http response in Node?

爱⌒轻易说出口 提交于 2020-01-15 10:11:45
问题 I have a big job that I fork to a child process. But I want the child process to handle the response instead of the main thread. So the child process generates a big old JSON object, but I don't want it to send it BACK to the main process. I just want it to send the response back itself. function doWork(req,res) { // CALL CHILD PROCESS, And have the child res.json(bigObject) } app.get('/dowork', doWork); I'd like this pass the response ('res'), so that the child writes back to it. Is there a

How to get child process to write to an http response in Node?

ぐ巨炮叔叔 提交于 2020-01-15 10:09:29
问题 I have a big job that I fork to a child process. But I want the child process to handle the response instead of the main thread. So the child process generates a big old JSON object, but I don't want it to send it BACK to the main process. I just want it to send the response back itself. function doWork(req,res) { // CALL CHILD PROCESS, And have the child res.json(bigObject) } app.get('/dowork', doWork); I'd like this pass the response ('res'), so that the child writes back to it. Is there a

“Access-Control-Allow-Origin” CORS issue when using Vue.js for client side and Express for server side

不羁的心 提交于 2020-01-15 10:06:08
问题 I'm trying to make a call to my API on Jazz using Vue.js and Axios, but I am getting the following error: Access to XMLHttpRequest at 'https://jazz.api.com/api/extra_stuff _here' from origin 'http://localhost' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. I've been looking at other solutions like https://enable-cors.org/server_expressjs.html or adding "Content-Type

“Access-Control-Allow-Origin” CORS issue when using Vue.js for client side and Express for server side

你离开我真会死。 提交于 2020-01-15 10:05:17
问题 I'm trying to make a call to my API on Jazz using Vue.js and Axios, but I am getting the following error: Access to XMLHttpRequest at 'https://jazz.api.com/api/extra_stuff _here' from origin 'http://localhost' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. I've been looking at other solutions like https://enable-cors.org/server_expressjs.html or adding "Content-Type

how to restrict access to many folders in node.js using express module

不想你离开。 提交于 2020-01-15 09:37:52
问题 I am using node.js and express as the route method, my route looks like: Set the website routes app.use('/public', express.static('./public')); app.use('/web', express.static('./web')); how can I set restrict access to 'public' and 'web' folders in one method, currently I am using two line, this code app.get('/public*', checkPermissions, function(req,res,next){ next(); }); app.get('/web*', checkPermissions, function(req,res,next){ next(); }); 回答1: The checkPermissions function should look

Inserts NULL - Node Js // MongoDB

Deadly 提交于 2020-01-15 09:36:47
问题 I don´t know why this code inserts NULL. When the post request is sent I receive (from res.json(req.body) in index.js) an empty "{}" I´m using NodeJs, Express 4 and MongoDB. The name attributes in the post are the same than in the jade template. I have two forms in the same .jade but with differents names, obviously. This is not all code, I just put the most important and what is related to the question App.js var express = require('express'); var bodyParser = require('body-parser'); var

Error 400 when making POST request to Spotify API with Axios on Express.js

走远了吗. 提交于 2020-01-15 08:57:06
问题 I'm trying to retrieve an access token from the Spotify API when making a post request with axios on an Express back end server. So far I have been unsuccessful. I'm getting the following error: data: { error: 'unsupported_grant_type', error_description: 'grant_type must be client_credentials, authorization_code or refresh_token' } } } I've already tried to change 'data' property for 'grant_type' to 'params' but it's still not working. Any advice would help. const express = require('express')

Node.js Rest call to a server that requires a certificate

微笑、不失礼 提交于 2020-01-15 06:06:05
问题 How do a make a rest call from Node.js to a server that requires a certificate for authentication? 回答1: The solution is to use a custom connection pool, for which you'll need to use a custom Agent. Here's an example using the standard https module, straight from the documentation: var options = { hostname: 'encrypted.google.com', port: 443, path: '/', method: 'GET', key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'), cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem') };