express

Request header field <field-name> is not allowed by Access-Control-Allow-Headers in preflight response

笑着哭i 提交于 2021-02-15 04:54:51
问题 I have a React app that is trying to make an axios request to my Express server to find a user in a Mongo database. Before, I built the back-end on Rails and had a gem for CORS, and after trying to configure CORS on the Express side, I can't seem to find a solution. I want to be able to pass in a custom field in headers (i.e. username) so I can use that field to query against my database. Error I get in browser: XMLHttpRequest cannot load http://localhost:3000/api/users/test. Request header

Resource was blocked due to MIME type mismatch using pug and node

筅森魡賤 提交于 2021-02-13 05:44:10
问题 I'm trying to render a view with an id in the url: router.get('/employee', authController.protect, viewsController.getOverviewEmployee); router.get('/employee/:id', authController.protect, viewsController.getOneEmployee); The /employee works fine, but when I get to the /employee/:id page the css and scripts won't load and the console shows me this error: The resource from “http://127.0.0.1:3000/employee/lib/bootstrap/css/bootstrapmin.css” was blocked due to MIME type (“application/json”)

req.body not working when using multipart/form-data in html form NodeJs/Express

会有一股神秘感。 提交于 2021-02-11 17:40:42
问题 I am using body-parser to get info requested from forms, but when I put enctype="multipart/form-data" in the header of the form, the req.body will not working at all. However, I have used multer lib in order to upload images as follow: app.post("/", function (req, res, next) { var button = req.body.button_name; if (button == "upload") { var UserId = 2; var imageUploadedLimited = 3; var storage = multer.diskStorage({ destination: function (req, file, callback) { var dir = "./public/images

express get routes : how to achieve DRY

最后都变了- 提交于 2021-02-11 17:23:08
问题 I have code like below to get process paths router.get( "/todoHome", ( req, res ) => { res.render( "todoHome", { title: 'My Todo List!!' } ); } ); router.get( "/articles", ( req, res ) => { res.render( "articles", { title: 'Articles To Read' } ); } ); router.get( ["/", "/index"] ( req, res ) => { res.render( "index", { title: 'Homepage' } ); } ); router.get( "/primary" ( req, res ) => { res.render( "primaryurls", { title: 'Primary DC URLs' } ); } ); router.get( "/standby" ( req, res ) => {

Proxying file upload with node/express.js and node request results in corrupt files with almost dobble the file size

会有一股神秘感。 提交于 2021-02-11 17:01:33
问题 I'm trying to proxy our main server via a node.js/express.js server. I've got everything working as it should except file uploads. Files are uploaded and reach the server, however somewhere between the data being passed over to node.js request and the data reaching the server the file is corrupted. A file with content-length 1833 ends up having a content-length 3274 once it reaches the server. I expect the file that reaches the server to stay at 1833. Running without the proxy works as

Proxying file upload with node/express.js and node request results in corrupt files with almost dobble the file size

馋奶兔 提交于 2021-02-11 17:00:42
问题 I'm trying to proxy our main server via a node.js/express.js server. I've got everything working as it should except file uploads. Files are uploaded and reach the server, however somewhere between the data being passed over to node.js request and the data reaching the server the file is corrupted. A file with content-length 1833 ends up having a content-length 3274 once it reaches the server. I expect the file that reaches the server to stay at 1833. Running without the proxy works as

Why is passport.deserializeUser called after req.user has been restored?

橙三吉。 提交于 2021-02-11 16:38:44
问题 According to the Passport Documentation on Sessions ...only the user ID is serialized to the session, keeping the amount of data stored within the session small. When subsequent requests are received, this ID is used to find the user, which will be restored to req.user. However my test SPA which is based on Passport form-based authentication sample with debug messages added indicates req.user has already been restored before the app.get route handler is triggered. Here is the output from an

Why is passport.deserializeUser called after req.user has been restored?

痞子三分冷 提交于 2021-02-11 16:37:13
问题 According to the Passport Documentation on Sessions ...only the user ID is serialized to the session, keeping the amount of data stored within the session small. When subsequent requests are received, this ID is used to find the user, which will be restored to req.user. However my test SPA which is based on Passport form-based authentication sample with debug messages added indicates req.user has already been restored before the app.get route handler is triggered. Here is the output from an

Why is passport.deserializeUser called after req.user has been restored?

两盒软妹~` 提交于 2021-02-11 16:37:06
问题 According to the Passport Documentation on Sessions ...only the user ID is serialized to the session, keeping the amount of data stored within the session small. When subsequent requests are received, this ID is used to find the user, which will be restored to req.user. However my test SPA which is based on Passport form-based authentication sample with debug messages added indicates req.user has already been restored before the app.get route handler is triggered. Here is the output from an

Sequelize hasMany is working fine but the inverse relation is not working

六月ゝ 毕业季﹏ 提交于 2021-02-11 15:54:00
问题 I am trying to work with mysql relations in Node Js(express Js) using Sequelize. User.hasMany(Post); work just fine, but when i try to inverse it in Post model like: Post.belongsTo(User); got this error: throw new Error(${source.name}.${_.lowerFirst(Type.name)} called with something that's not a subclass of Sequelize.Model); Error: post.belongsTo called with something that's not a subclass of Sequelize.Model User model like: const Sequelize = require('sequelize'); const db = require('..