1、egg简述
Egg.js,为企业级框架和应用而生,是阿里开源的企业级 Node.js 框架。
2、特点
Egg 奉行『约定优于配置』,按照一套统一的约定进行应用开发,团队内部采用这种方式可以减少开发人员的学习成本。
基于 Koa 开发,性能优异。
3、基于eggjs的 restful api示例
https://github.com/MengFangui/eggjs-api
4、跨域的解决
1)安装依赖包
npm i egg-cors --save
or
yarn add egg-cors
2)在plugin.js中设置开启cors
exports.cors = {
enable: true,
package: 'egg-cors',
};
3)在config.default.js中配置
config.security = {
csrf: {
enable: false,
ignoreJSON: true
},
domainWhiteList: ['http://localhost:8080']
};
config.cors = {
origin:'*',
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH'
};
说明需要配置security ,不然会报403权限错误。
网友评论