请选择 进入手机版 | 继续访问电脑版
  • 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

postbird/koa-generator-postbird: kao2 开发脚手架,集成了 koaBody/nunjucks/koa-ro ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

postbird/koa-generator-postbird

开源软件地址:

https://github.com/postbird/koa-generator-postbird

开源编程语言:

JavaScript 63.6%

开源软件介绍:

koa-generator-postbird | koa2 开发脚手架

集成了 koa-body / nunjucks / koa-router / koa-session 的开发脚手架。

项目地址:

一、基本依赖

  • 路由:koa-router
  • cookie: koa2 默认的 cookie
  • session: koa-session
  • post 请求和文件上传: koa-body
  • 模板引擎:nunjucks,使用的依赖 koa-nunjucks-2
  • 静态资源: koa-static

二、目录结构

+ config // 配置
      |-- app.js // 应用层级配置
+ controllers // 控制器方法
+ middlewares // 中间件方法
+ models // 模型方法或数据生成
+ public 
      |-- css // stylesheet
      |-- js // scripts
      |-- vendor // 第三方依赖
      |-- upload // 文件上传路径
+ routes // 路由方法
      |-- index.js // 主路由加载
      |-- home.js // 首页路由及其他路由
+ tests // 测试方法
+ utils // 工具方法
+ views // 模板文件
      |-- base.html // 模板布局基础模板
      |-- index.html // 默认首页模板
+ app.js // 服务入口
+ nodemon.json // nodemon 配置文件

三、使用方式:

1、克隆项目

git clone https://github.com/postbird/koa-generator-postbird

2、安装依赖

yarn install

## npm install

3、开启服务

以开发模式运行 app.js, 需要全局安装 nodemon

npm install -g nodemon

yarn dev 

## npm run dev

通过 node 运行 app.js

yarn start

## npm run start

四、配置文件 config/app.js

/**
 * @description app的配置参数
 */
module.exports = {
  point:'3000', // 端口
  staticDir:'./public', // 静态资源配置目录
  viewsDir:'./views', // 模板文件目录
  viewsExt:'html', // 模板的后缀
  session:{
    key: 'koa:sess',   //cookie key (default is koa:sess)
    maxAge: 86400000,  // cookie的过期时间 maxAge in ms (default is 1 days)
    overwrite: true,  //是否可以overwrite    (默认default true)
    httpOnly: true, //cookie是否只有服务器端可以访问 httpOnly or not (default true)
    signed: true,   //签名默认true
    rolling: false,  //在每次请求时强行设置cookie,这将重置cookie过期时间(默认:false)
    renew: false,  //(boolean) renew session when session is nearly expired,
  },
  upload:{
    size:2*2014*1024, // 文件上传大小
    dir:"public/upload" // 文件上传路径
  }
};

五、文件上传

使用 koa-body 进行文件上传,基本采用默认配置,如果需要自定义文件名请参照:

六、效果

demo.jpg

License

MIT




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap