mirror of
				https://github.com/KevinMidboe/leifsbackend.git
				synced 2025-10-29 17:50:20 +00:00 
			
		
		
		
	Defined correct cors requirements for options and Access-Control-Allow-Origin to all requestes.
This commit is contained in:
		
							
								
								
									
										13
									
								
								src/app.js
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/app.js
									
									
									
									
									
								
							@@ -3,10 +3,23 @@ const logger = require('morgan')
 | 
				
			|||||||
const bodyParser = require('body-parser')
 | 
					const bodyParser = require('body-parser')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const app = express();
 | 
					const app = express();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app.use(logger('dev'));
 | 
					app.use(logger('dev'));
 | 
				
			||||||
app.use(bodyParser.json());
 | 
					app.use(bodyParser.json());
 | 
				
			||||||
app.use(bodyParser.urlencoded({ extended: false }));
 | 
					app.use(bodyParser.urlencoded({ extended: false }));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app.options("/*", function(req, res, next){
 | 
				
			||||||
 | 
					  res.header('Access-Control-Allow-Origin', 'http://localhost:8080');
 | 
				
			||||||
 | 
					  res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
 | 
				
			||||||
 | 
					  res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
 | 
				
			||||||
 | 
					  res.send(200);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app.all('/*', function(req, res, next) {
 | 
				
			||||||
 | 
					  res.header('Access-Control-Allow-Origin', 'http://localhost:8080')
 | 
				
			||||||
 | 
					  next();
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require('./routes')(app);
 | 
					require('./routes')(app);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app.get('*', (req, res) => res.status(200).send({
 | 
					app.get('*', (req, res) => res.status(200).send({
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user