{"type": "session", "harness": "deepseek-harness", "id": "sys-0040", "name": "CORS configuration"} {"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}} {"type": "message", "message": {"role": "user", "content": "How do I configure CORS properly?"}} {"type": "message", "message": {"role": "assistant", "content": "```javascript\n// Express.js\nconst cors = require('cors');\n\n// Allow specific origins\napp.use(cors({\n origin: ['https://app.example.com', 'https://admin.example.com'],\n methods: ['GET', 'POST', 'PUT', 'DELETE'],\n allowedHeaders: ['Content-Type', 'Authorization'],\n credentials: true,\n maxAge: 86400\n}));\n\n// Manual CORS headers\napp.use((req, res, next) => {\n const allowedOrigins = ['https://app.example.com'];\n const origin = req.headers.origin;\n if (allowedOrigins.includes(origin)) {\n res.setHeader('Access-Control-Allow-Origin', origin);\n }\n res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');\n res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');\n res.setHeader('Access-Control-Max-Age', '86400');\n if (req.method === 'OPTIONS') {\n return res.sendStatus(204);\n }\n next();\n});\n\n// nginx\n# add_header Access-Control-Allow-Origin \"https://app.example.com\" always;\n# add_header Access-Control-Allow-Methods \"GET, POST, OPTIONS\" always;\n# add_header Access-Control-Allow-Headers \"Content-Type, Authorization\" always;\n# if ($request_method = OPTIONS) { return 204; }\n```"}}