cors
This commit is contained in:
		
							parent
							
								
									f283b9d8e1
								
							
						
					
					
						commit
						5196cb9811
					
				
							
								
								
									
										18
									
								
								gateway.cjs
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								gateway.cjs
									
									
									
									
									
								
							|  | @ -5,8 +5,26 @@ const redis   = new Redis({ host: process.env.REDIS_HOST || "data_jobs", | ||||||
|                             port: Number(process.env.REDIS_PORT || 6379) }); |                             port: Number(process.env.REDIS_PORT || 6379) }); | ||||||
| const JOBS    = process.env.JOB_QUEUE    || "grist:jobs"; | const JOBS    = process.env.JOB_QUEUE    || "grist:jobs"; | ||||||
| const RESULTS = process.env.RESULT_QUEUE || "grist:results"; | const RESULTS = process.env.RESULT_QUEUE || "grist:results"; | ||||||
|  | const ALLOW_ORIGIN = process.env.ALLOW_ORIGIN || "https://map.arenos.danielnagel.at"; | ||||||
| 
 | 
 | ||||||
| http.createServer(async (req, res) => { | http.createServer(async (req, res) => { | ||||||
|  | 
 | ||||||
|  |   // ---- CORS Header immer mitsenden ----
 | ||||||
|  |   res.setHeader("Access-Control-Allow-Origin", ALLOW_ORIGIN); | ||||||
|  |   res.setHeader("Vary", "Origin"); | ||||||
|  | 
 | ||||||
|  |   // Preflight (OPTIONS) beantworten
 | ||||||
|  |   if (req.method === "OPTIONS") { | ||||||
|  |     res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS"); | ||||||
|  |     res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization"); | ||||||
|  |     // wenn du Auth/Cookies brauchst:
 | ||||||
|  |     // res.setHeader("Access-Control-Allow-Credentials", "true");
 | ||||||
|  |     res.statusCode = 204; | ||||||
|  |     return res.end(); | ||||||
|  |   } | ||||||
|  |   // -------------------------------------
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|   if (req.method === "POST" && req.url === "/api/job") { |   if (req.method === "POST" && req.url === "/api/job") { | ||||||
|     const stream = await readJsonBody(req);                  // JSON Stream vom Client. mit readJsonBody() wieder zurück in JSON.
 |     const stream = await readJsonBody(req);                  // JSON Stream vom Client. mit readJsonBody() wieder zurück in JSON.
 | ||||||
|     await redis.lpush(JOBS, JSON.stringify(stream));         // Job in Queue. Als String in Redis eintragen. Der Worker nimmt dann den String.
 |     await redis.lpush(JOBS, JSON.stringify(stream));         // Job in Queue. Als String in Redis eintragen. Der Worker nimmt dann den String.
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user