系统相关
首页 > 系统相关> > 14.7 nginx跨域

14.7 nginx跨域

作者:互联网

编辑nginx文件  vi /usr/local/etc/nginx/nginx.conf
nginx配置如下,配置后需重启nginx nginx -s reload
location ~.*\.json {
    root html;
    add_header "Access-Control-Allow-Origin" "*";
}

前端
index.html
<script>
fetch('http://localhost:1207/a.json',  {
  method: 'get'
})
.then(res => {
  return res.text()
}).then(res => {
  console.log(res)
})
</script>

后端

index.js

let express = require('express')
let app  = express()
app.use(express.static(__dirname))
app.listen(3000)

 

 

 

标签:14.7,跨域,res,app,express,nginx,json,html
来源: https://www.cnblogs.com/zouxinping/p/10357726.html