express

Express - 400 bad request on POST and PUT

荒凉一梦 提交于 2020-03-05 05:32:08
问题 I'd like some help as I'm new to Node.js and express. I have the following code which I'm testing on Postman const Joi = require('@hapi/joi'); const bodyParser = require('body-parser'); // Load the express framework const express = require('express'); const app = express(); app.use(express.json()); app.use(bodyParser.json()); app.use(express.urlencoded({ extended: true })); // temp array const courses = [ {id: 1, title: 'Learning Node.js'}, {id: 2, title: 'How to become a full stack dev'},

Can I set a dynamic cors policy which only allows specific origins to pass cookies (Node.js)?

拜拜、爱过 提交于 2020-03-05 04:44:26
问题 Context I have an express server with two types of clients. My app (React + graphql): I've enabled credentials for this client: app.use(cors({ credentials: true, origin: "http://localhost:3000" })); I've set this so that I can receive auth-related cookies from my gql client. Third-party services (via http client I provide). These requests can come from any number of origins. I can't use the wildcard operator for the orgin ( cors({origin: *}) ) as this would allow any site to use my users'

mongodb insert data into the array of objects and update it

二次信任 提交于 2020-03-05 03:01:06
问题 I need to make a vote, it looks like an array of objects, look like the user’s ID and the value that he set. If the user has already voted, but changed his value, you need to change the value of the rate in the array of objects for this user. I need to make an array of objects into which data will be inserted like this {rate: 3, user: "asdr2r24f2f42f24"} and if the user has already voted in this array, then you need to change the value rate of the given user I already tried to do something,

Mongoose use user input to find results in DB with express.js?

我与影子孤独终老i 提交于 2020-03-05 00:38:21
问题 I'm new to mongoose/mongo and express so I'm not quiet sure how to go about this. So basically I'm trying to use checkboxes to sort of "filter" results in my database. Here's an example of something in my db: { "location" : "PHARMACY", "region" : "SOCAL", "system" : "WITS", "contact" : "SMITH", "membership" : "TIER1" } So far I've only figured out how to hard code it like this, where I do Environment.find({region: "SOCAL"}) and it spits out all the db entries that contain SOCAL as a region:

Mongoose use user input to find results in DB with express.js?

寵の児 提交于 2020-03-05 00:36:40
问题 I'm new to mongoose/mongo and express so I'm not quiet sure how to go about this. So basically I'm trying to use checkboxes to sort of "filter" results in my database. Here's an example of something in my db: { "location" : "PHARMACY", "region" : "SOCAL", "system" : "WITS", "contact" : "SMITH", "membership" : "TIER1" } So far I've only figured out how to hard code it like this, where I do Environment.find({region: "SOCAL"}) and it spits out all the db entries that contain SOCAL as a region:

How to catch FacebookAuthorizationError in passport-facebook / Passport.js?

前提是你 提交于 2020-03-04 23:29:38
问题 I have an express app that uses Facebook authentication via Passport.js and the passport-facebook strategy. I have followed the documentation on how to handle authentication. It all works fine... until Facebook tries to report an error via the callback Url. In this case, I get an uncaught FacebookAuthorizationError exception, and the failureRedirect is not called. End users see an "Internal Server Error" as a result of the un-caught exception and I am in non-compliance with Facebook

How to catch FacebookAuthorizationError in passport-facebook / Passport.js?

不羁的心 提交于 2020-03-04 23:28:19
问题 I have an express app that uses Facebook authentication via Passport.js and the passport-facebook strategy. I have followed the documentation on how to handle authentication. It all works fine... until Facebook tries to report an error via the callback Url. In this case, I get an uncaught FacebookAuthorizationError exception, and the failureRedirect is not called. End users see an "Internal Server Error" as a result of the un-caught exception and I am in non-compliance with Facebook

Express.js application bug: delete post route is not found

廉价感情. 提交于 2020-03-04 18:18:13
问题 I am working on a blogging application (click the link to see the GitHub repo) with Express, EJS and MongoDB. I have been unable to delete a post via AJAX. In my Dashboard routes file ( routes\admin\dashboard.js ) I have: // Delete Post router.delete('/post/delete/:id', dashboardController.deletePost); In my Dashboard controller: exports.deletePost = (req, res, next) => { const postId = req.params.id; posts.findByIdAndRemove(postId, function(err){ if (err) { console.log('Error: ', err); } res

Update data with NodeJs [duplicate]

こ雲淡風輕ζ 提交于 2020-03-04 17:52:12
问题 This question already has answers here : SQL if not null update (5 answers) Closed last month . I am trying to update my user data in database with node app (using expressJs) but it returns this error in terminal: sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL WHERE `id` = '1'' at line 1", sqlState: '42000', index: 0, sql: "UPDATE `users` SET NULL WHERE `id` = '1'" Code index.js var Users