ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
# 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) ~~~