express

Express JS is receiving an empty req.body from ReactJS

前提是你 提交于 2021-01-07 04:10:51
问题 I am currently having a problem with React and Express JS form submit function. It seems like my nodeJS running on port 5000 is receiving an empty object from my ReactJS running on port 8080 using fetch method. React : Contact.js handleSubmit(e) { e.preventDefault(); var data = { name: this.state.name, contact: this.state.contact, email: this.state.email, message: this.state.message, } var url = 'http://localhost:5000/api/insertUsers'; fetch(url, { method: 'POST', headers: { 'Content-Type':

Express JS is receiving an empty req.body from ReactJS

╄→尐↘猪︶ㄣ 提交于 2021-01-07 04:10:46
问题 I am currently having a problem with React and Express JS form submit function. It seems like my nodeJS running on port 5000 is receiving an empty object from my ReactJS running on port 8080 using fetch method. React : Contact.js handleSubmit(e) { e.preventDefault(); var data = { name: this.state.name, contact: this.state.contact, email: this.state.email, message: this.state.message, } var url = 'http://localhost:5000/api/insertUsers'; fetch(url, { method: 'POST', headers: { 'Content-Type':

Express JS is receiving an empty req.body from ReactJS

情到浓时终转凉″ 提交于 2021-01-07 04:08:16
问题 I am currently having a problem with React and Express JS form submit function. It seems like my nodeJS running on port 5000 is receiving an empty object from my ReactJS running on port 8080 using fetch method. React : Contact.js handleSubmit(e) { e.preventDefault(); var data = { name: this.state.name, contact: this.state.contact, email: this.state.email, message: this.state.message, } var url = 'http://localhost:5000/api/insertUsers'; fetch(url, { method: 'POST', headers: { 'Content-Type':

How to export a variable which is in a class in Nodejs

落爺英雄遲暮 提交于 2021-01-07 03:59:27
问题 This is my file loginHandler.js class LoginHandler { merchantId = ''; returnURLForIframe(req, res) { merchantId = req.params.merchantId; } } module.exports = new LoginHandler(); I want to access the variable merchantId on another file const loginHandler = require('./loginHandler') class ResponseHandler { getResponseFromCOMM(options,token, res){ console.log(loginHandler.merchantId) } } But merchantId is undefined. Can you please tell me what I am doing wrong? Here you can see the code on

Deploying react/apollo-server app onto Heroku

假装没事ソ 提交于 2021-01-07 03:33:08
问题 What I'm trying to do is deploy react / apollo-server full stack app to heroku. Thus I' trying to serve static client files from express/apollo-server backend, like this: const path = require('path'); const express = require('express'); const app = express(); const cors = require('cors'); const { ApolloServer } = require('apollo-server'); const { schema } = require('./schema'); const { resolvers } = require('./resolvers'); app.use(cors()); app.use(express.static('public')); app.get('*', (req,

Why CSRF is not working in only POST route While working in the rest of other Post routes?

你说的曾经没有我的故事 提交于 2021-01-07 03:32:31
问题 I am getting the CSRF forbidden error . However CSRF is working fine in the rest of the application like post route of logout, signUp, Signin deleteing anything et c.. But when I perform the post action in only one route `/addProduct" I am getting the error Note that I am generating my CSRF token before routes declaration. I am attaching the main file code and the front end code of addProduct. Here is my main file code where I am generating token and including it in all routes app.use

Deploying react/apollo-server app onto Heroku

☆樱花仙子☆ 提交于 2021-01-07 03:32:04
问题 What I'm trying to do is deploy react / apollo-server full stack app to heroku. Thus I' trying to serve static client files from express/apollo-server backend, like this: const path = require('path'); const express = require('express'); const app = express(); const cors = require('cors'); const { ApolloServer } = require('apollo-server'); const { schema } = require('./schema'); const { resolvers } = require('./resolvers'); app.use(cors()); app.use(express.static('public')); app.get('*', (req,

Mark all properties as required or not Joi

徘徊边缘 提交于 2021-01-07 03:09:01
问题 I'm building an Express API and using @hapi/joi for validation. However I find myself in the following situation: if I want to validate a new user, all the properties in the schema have to be required, but if the client wants to modify a user, these properties must be optional since only the client knows what properties it will modify. So if I have this schema for new users : function validateUser(user) { const schema = Joi.object().keys({ name: Joi.string().required(), lastName: Joi.string()

How to use socket io instance on multiple files in express.js app

坚强是说给别人听的谎言 提交于 2021-01-07 03:00:11
问题 In my express app, generated with express-generator , I want to use the io of socket.io in some other controller files to emit data to client sockets. My approach is below, but I get the following error with that. It would be a great favor if someone can help me in this case. (node:11376) UnhandledPromiseRejectionWarning: TypeError: io.emit is not a function at F:\backend\controllers\LessonController.js:169:9 In the express apps, generated by express-generator , the process of creating the

JsonWebTokenError: jwt malformed (creating an API in ExpressJs)

允我心安 提交于 2021-01-07 02:57:15
问题 I've checked many answers on the internet but I think I'm doing some other mistake also. My question is strictly related to guarding /contribute route using JWT (which is a POST request). My API is in expressjs . First I hit /login route with correct credentials and get a token. This token I cross checked on jwt.io and it says "Invalid Signature". Here is that token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWJqZWN0IjoiNWVhZDlkOGY4N2VjMjkwMDE3YzRkODkzIiwiaWF0IjoxNjA3ODczNjY2fQ.H5RI-lOBzfJo4