NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
# http-server跨域 ~~~ const http = require('http'); var data = { name:"chengchao" } const server = http.createServer((req,res)=>{ res.writeHead(200,{ 'Content-Type':'application/json', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST' }) res.end(JSON.stringify(data)); }) server.listen(8080) ~~~ # 3-2 koa-跨域 ~~~ const koa = require('koa'); const app = new koa(); app.use(async ctx=>{ ctx.set('Access-Control-Allow-Origin','*') ctx.body = {name:"chengchao"} }) app.listen(8080) ~~~