express

How to pass Header JWT Token with Axios & React?

人走茶凉 提交于 2020-05-24 21:54:13
问题 I make web application with React, Express, MongoDB. And, I want to pass jwt token with header. But, I pass it, get 401 error (Unauthorized). In login actions.js : export function login(username, password) { return function(dispatch) { axios .post(`${API_URL}/auth/login`, { username, password }) .then(res => { dispatch(loginSuccess(res.data, username)); const token = res.data.token; axios.defaults.headers.common["Authorization"] = token; history.push("/"); }) .catch(err => { if (err.response

How to pass Header JWT Token with Axios & React?

☆樱花仙子☆ 提交于 2020-05-24 21:54:06
问题 I make web application with React, Express, MongoDB. And, I want to pass jwt token with header. But, I pass it, get 401 error (Unauthorized). In login actions.js : export function login(username, password) { return function(dispatch) { axios .post(`${API_URL}/auth/login`, { username, password }) .then(res => { dispatch(loginSuccess(res.data, username)); const token = res.data.token; axios.defaults.headers.common["Authorization"] = token; history.push("/"); }) .catch(err => { if (err.response

ExpressJS Server - How to handle multiple domains

眉间皱痕 提交于 2020-05-24 08:18:52
问题 I'm fooling around a little with Express and I'm wondering, what the "most correct" way is to handle multiple domains which are linked to the same server. Lets assume we have foo.com bar.net baz.com which all point to 111.222.333.444 . That machine is running NodeJS with Express. My current solution looks like this: var express = require( 'express' ), app = module.exports = express.createServer(), // ... more lines ... app.get( '/', routes.index.bind( app ) ); Thus far this is pretty

How can I return a valid JSON response with React-Router and an Express backend?

风流意气都作罢 提交于 2020-05-24 04:55:44
问题 I have a setup similar to the one in this tutorial. How can I render JSON alone (no HTML) without having to specify the port number for the route specified in index.js ? Within my own setup, I can view JSON by visiting https://socialmaya.com/u/real but can't get an actual JSON response unless I visit http://socialmaya.com:5000/actors/real, which is what's being called by React. Here is my code which is an attempt to implement an ActivityPub API for a social network built using the MERN stack.

How can I return a valid JSON response with React-Router and an Express backend?

放肆的年华 提交于 2020-05-24 04:54:31
问题 I have a setup similar to the one in this tutorial. How can I render JSON alone (no HTML) without having to specify the port number for the route specified in index.js ? Within my own setup, I can view JSON by visiting https://socialmaya.com/u/real but can't get an actual JSON response unless I visit http://socialmaya.com:5000/actors/real, which is what's being called by React. Here is my code which is an attempt to implement an ActivityPub API for a social network built using the MERN stack.

Angular 9 universal Error: Component 'HeaderComponent' is not resolved:

江枫思渺然 提交于 2020-05-24 03:32:07
问题 After update to angular 9 and universal 9, a got error when i run npm run build:ssr && npm run serve:ssr Error: Component 'HeaderComponent' is not resolved: - templateUrl: ./header.component.html - styleUrls: ["./header.component.scss"] Did you run and wait for 'resolveComponentResources()'? at Function.get (D:\projects\my-app\node_modules\@angular\core\bundles\core.umd.js:26828:31) at getComponentDef (D:\projects\my-app\node_modules\@angular\core\bundles\core.umd.js:2021:20) at

Angular 9 universal Error: Component 'HeaderComponent' is not resolved:

百般思念 提交于 2020-05-24 03:30:24
问题 After update to angular 9 and universal 9, a got error when i run npm run build:ssr && npm run serve:ssr Error: Component 'HeaderComponent' is not resolved: - templateUrl: ./header.component.html - styleUrls: ["./header.component.scss"] Did you run and wait for 'resolveComponentResources()'? at Function.get (D:\projects\my-app\node_modules\@angular\core\bundles\core.umd.js:26828:31) at getComponentDef (D:\projects\my-app\node_modules\@angular\core\bundles\core.umd.js:2021:20) at

SequelizeConnectionError: self signed certificate

寵の児 提交于 2020-05-23 17:34:03
问题 I am trying to connect to a PostgreSQL Database that I've set up in Heroku. const { Sequelize, DataTypes, Model } = require("sequelize"); // DB Configuration const sequelize = new Sequelize({ database: "[wont'd show db]", username: "[won't show username]", password: "[won't show password]", host: "ec2-54-221-195-148.compute-1.amazonaws.com", port: 5432, dialect: "postgres", dialectOptions: { ssl: true, }, }); And this is what I am getting as the output: SequelizeConnectionError: self signed

SequelizeConnectionError: self signed certificate

廉价感情. 提交于 2020-05-23 17:33:26
问题 I am trying to connect to a PostgreSQL Database that I've set up in Heroku. const { Sequelize, DataTypes, Model } = require("sequelize"); // DB Configuration const sequelize = new Sequelize({ database: "[wont'd show db]", username: "[won't show username]", password: "[won't show password]", host: "ec2-54-221-195-148.compute-1.amazonaws.com", port: 5432, dialect: "postgres", dialectOptions: { ssl: true, }, }); And this is what I am getting as the output: SequelizeConnectionError: self signed

Node.js Mongoose .update with ArrayFilters

三世轮回 提交于 2020-05-23 10:01:45
问题 As it stands, I am able to get this functionality working using the Mongo shell, but having issues with the nested arrays inside of Node.js using Mongoose. Mongo shell command that is successful: db.test.update({}, {$set: {"this.$[i].that.$[x].amnt": 10000}}, {arrayFilters: [{"i._id": ObjectId('5a568059bc44142a9ca33d09')}, {"x.userId": ObjectId('5a466acb864c752f8c9890c6')}]}) Result: changed the amnt field to 10000. There was no matches returned until calling ObjectId('') on the given strings