1. const app = Koa()
    2. app.use((req, res, next) => {
    3. // res.header("Access-Control-Allow-Origin", "*")
    4. res.header("Access-Control-Allow-Origin", "http://localhost:8080")
    5. res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Content-Length, Accept, Authorization")
    6. res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS,HEAD")
    7. res.header("X-Powered-By",' 3.2.1')
    8. res.header("Content-Type", "application/json;charset=utf-8")
    9. // 支持 cookie
    10. res.header('Access-Control-Allow-Credentials', true)
    11. // 屏蔽 OPTIONS
    12. if (req.method.toLowerCase() === 'options') {
    13. return res.send()
    14. }
    15. next()
    16. })