File-upload-Angular2-Nodejs
File-upload-Angular2-Nodejs copied to clipboard
Access-Control-Allow-Origin
check screensort for error
i am trying to access same code but still i am getting error can you help for solve this
XMLHttpRequest cannot load http://localhost:3650/upload. Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'http://localhost:3000' that is not equal to the supplied origin. Origin 'http://localhost:3002' is therefore not allowed access.
Any updates on this issue ? any hack for the same ?
This is not an issue with the code, it's related to browser security when making cross-origin requests. Change this line to the address from where you are making api requests. https://github.com/rahil471/File-upload-Angular2-Nodejs/blob/master/node-app/app.js#L8
Error: "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at ‘http://localhost:3000/uploads’. (Reason: Credential is not supported if the CORS header ‘Access-Control-Allow-Origin’ is ‘*’)." ---->>> with cors installed.
This is because in "ng2-file-upload" module, the "Credential" are set to "true" in several files. Even using cors doesn't fix this problem because Credentials can't be on using ‘Access-Control-Allow-Origin’: "*".
Installing "cors" should disable all the security built into "ng2-file-upload" or it is not useful for development purposes as everyone builds and tests on one machine usually.
~ SC
I am using passport-saml for authenticating users to SSO. It was working fine when both were running on same port**.I am not able to redirect to login.** If I use URL in browser ‘http://usdf13v0412_dev_tushar:4200/' It’s going to my middle-ware.It’s logging this code: console.log(‘isAuthenticated middleware failed ! ‘); If I us URL in browser http://usdf13v0412_dev_tushar:3000/xyz I am able to redirect to login.
`const originsWhitelist = [‘http://usdf13v0412_dev_tushar:4200/']; const corsSettings = { origin: function (origin, callback) { const isWhitelisted = originsWhitelist.indexOf(origin) !== -1; callback(null, isWhitelisted); }, credentials: true }; app.use(cors(corsSettings)); app.get(‘/’, ensureAuthenticated, function (req, res,next) { console.log(‘redirect to UI’); res.redirect(‘http://usdf13v0412_dev_tushar:4200/'); });
app.get(‘/login’, passport.authenticate(passportSamlConfig.passport.strategy, { failureRedirect: ‘/login’ }), function (req, res, next) { console.log(‘Login done!’); next(); }); app.post(‘/assert’, passport.authenticate(passportSamlConfig.passport.strategy, { failureRedirect: ‘/login’ }), function (req, res) { //console.log(‘Recive user details from saml done!’); res.redirect(‘/’); res.end(); });
function ensureAuthenticated(req, res, next) { console.log(‘aruth middleware!’); if (req.isAuthenticated()) { console.log(‘isAuthenticated middleware sucess ! ‘); next(); } else { console.log(‘isAuthenticated middleware failed ! ‘); return res.redirect(‘http://usdf13v0412_dev_tushar:3000/login'); } }`