All Projects → zhaotoday → Less.js

zhaotoday / Less.js

a Node.js MVC framework based on Koa.js. 基于 Koa.js 的 Node.js MVC 框架。

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Less.js

Mysrv
Yet another Node.js web framework, based on koa.js 又一个 Node.js MVC 框架,基于Koa2
Stars: ✭ 10 (-81.13%)
Mutual labels:  koa2, mvc
Danvic.psu
This is my graduation project of dotnet core version
Stars: ✭ 46 (-13.21%)
Mutual labels:  mvc
Recife
A powerful MVC Framework for GraphQL
Stars: ✭ 20 (-62.26%)
Mutual labels:  mvc
Koa Typescript
🚀️koa2 & typescript
Stars: ✭ 38 (-28.3%)
Mutual labels:  koa2
Rankmusic
RankMusic音乐排行榜 一个使用kotlin 语言开发的android项目。
Stars: ✭ 30 (-43.4%)
Mutual labels:  mvc
Mini Shop
A Vue.js project for "零食商贩"
Stars: ✭ 41 (-22.64%)
Mutual labels:  koa2
Koahub Demo
koahub+async/await+mysql
Stars: ✭ 15 (-71.7%)
Mutual labels:  koa2
Koa Typescript Starter
Integrating TypeScript with KOA2 to hit the ground running faster
Stars: ✭ 51 (-3.77%)
Mutual labels:  koa2
K2
Koa2 API template with passport, GraphQL, flowtype, knex and more.
Stars: ✭ 44 (-16.98%)
Mutual labels:  koa2
Tom Vpr
how does voiceprint recognition work in wechat page
Stars: ✭ 37 (-30.19%)
Mutual labels:  koa2
Codegen
A model-view based code generator written in Java
Stars: ✭ 36 (-32.08%)
Mutual labels:  mvc
Littlewin.server
A blog backend server based on koa + mongoose.
Stars: ✭ 32 (-39.62%)
Mutual labels:  koa2
Javaserverfaces Spec
JavaServer(TM) Faces Specification web site
Stars: ✭ 42 (-20.75%)
Mutual labels:  mvc
Jetweet
Jetweet is a mini twitter clone with basic functionalities, Made using ASP.NET CORE and Entity framework technologies
Stars: ✭ 29 (-45.28%)
Mutual labels:  mvc
Bast
Simple but Elegant Web Framework
Stars: ✭ 49 (-7.55%)
Mutual labels:  mvc
Ffcms
FFCMS 3 project distributive
Stars: ✭ 15 (-71.7%)
Mutual labels:  mvc
Docker Vue Node Nginx Mongodb Redis
🐉 An awesome boilerplate, Integrated Docker, Vue, Node, Nginx, Mongodb and Redis in one, Designed to develop & build your web applications more efficient and elegant.
Stars: ✭ 34 (-35.85%)
Mutual labels:  koa2
Razzle Unrouted
Blazingly fast server-rendered MVC Webapps with Preact and Webpack
Stars: ✭ 39 (-26.42%)
Mutual labels:  mvc
Epitome
Epitome is a MVC* (MVP) framework for MooTools.
Stars: ✭ 51 (-3.77%)
Mutual labels:  mvc
Egg Authz
egg-authz is an authorization middleware for Egg.js based on Casbin
Stars: ✭ 50 (-5.66%)
Mutual labels:  koa2

简介

版本

  • v3.0.1 [2019-10-30] 重构、性能优化、废除对视图层(view)的支持;
  • v2.0.9 [2019-04-11] 性能优化;
  • v2.0.0 [2019-02-15] 取消内置第三方 SDK;
  • v1.1.4 [2018-12-29] 支持 URL Rewrite;
  • v1.1.0 [2018-12-27] 支持 Redis 数据库,通过 ORM 框架 jugglingdb 操作 Redis;
  • v1.0.9 [2018-12-23] 支持同步 MySQL 数据库模型;
  • v1.0.8 [2018-12-20] 支持根据 controllers 目录结构自动生成对应路由,无需手动配置路由;
  • v1.0.5 [2018-12-10] 取消 koa-jwt 中间件,在 controller 基础类中进行 JWT 校验;

待办

  • 同步 MySQL 数据至 Redis;

示例

示例代码

请查看 example 文件夹。

管理后台代码

请访问 https://github.com/zhaotoday/iview

线上示例

请访问 https://admin.cmsx.cn/

账号:admin
密码:123456

注:按 F12 打开 Chrome 开发者工具查看接口请求。

运行

Node.js 版本

Koa2 使用了 async/await 等新语法,请保证 Node.js 版本在 7.6 及以上。

应用配置

修改 package.json,将 {app-name} 改成自己的:

{
  ...,
  "scripts": {
    "stop": "pm2 stop {app-name}"
  },
  ...
}

修改 processes.json,将 {app-name} 改成自己的:

{
  "apps": [
    {
      "name": "{app-name}",
      ...
    },
    ...
  ]
}

命令

# 安装 pm2 到全局
$ npm install -g pm2

# 安装 less.js
$ npm install --save less.js

# JS 代码校验
$ npm run eslintfix
$ npm run eslint

# 开发调试
$ npm run dev

# 启动项目
$ npm run start:dev

# 同步数据库模型
$ npm run sync-models:dev

# 停止项目
$ npm run stop

注::dev 表示执行命令时调用的是开发环境的配置。dev 表示开发环境,test 表示测试环境,beta 表示预生产环境,prod 表示生产环境。

目录结构

整体目录结构

├─ src                     源码
│  ├─ app                  业务代码
│  │  ├─ controllers       控制器:用于解析用户输入,处理后返回相应的结果
│  │  ├─ models            模型  :用于定义数据模型
│  │  └─ services          服务  :用于编写业务逻辑层,比如连接数据库,调用第三方接口等
│  │
│  ├─ config               配置
│  ├─ extends              扩展
│  ├─ middlewares          中间件
│  ├─ public               静态资源
│  ├─ redis                Redis 数据库
│  ├─ router               URL 路由
│  ├─ utils                工具库
│  └─ index.js             入口:用于自定义启动时的初始化工作,比如启动 https,调用中间件、路由等
│  
├─ .eslintrc               eslint 配置文件
├─ nodemon.json            nodemon 配置文件
├─ package.json            npm 配置文件
├─ processes.json          pm2 配置文件

配置(config)目录结构

├─ config                  配置
│  ├─ base.js              基础配置
│  ├─ development.js       开发环境配置
│  ├─ test.js              测试环境配置
│  ├─ beta.js              预生产环境配置
│  └─ production.js        生产环境配置

扩展(extends)目录结构

├─ extends                 扩展
│  ├─ controller.js        对控制器进行扩展
│  ├─ helpers.js           对辅助函数进行扩展
│  ├─ initialize.js        初始化
│  └─ service.js           对服务进行扩展

控制器(controllers)目录结构

├─ controllers          控制器
│  └─ v1                接口版本
│     ├─ admin          管理接口
│     │  ├─ actions     动作类接口
│     │  │
│     │  ├─ articles.js articles 接口控制器
│     │  └─ files.js    files 接口控制器
│     │
│     ├─ public         公开接口(无需鉴权即可调用)
│     │
│     └─ some-app       某个应用的接口

扩展

对 Koa.js 的一些扩展,用 $ 前缀命名,与 Koa.js 内置对象做区分。

app.$config:配置
app.$module:加载内置模块
app.$helpers:辅助函数
app.$resources:生成 RESTful 规范的路由
app.$model:公用模型对象
app.$Service:服务基类
app.$Controller:控制器基类
app.$models:模型集合
app.$services:服务集合
app.$controllers:控制器集合

如扩展辅助函数,请新建 src/extends/helpers.js:

module.exports = app => {
  return {
    myFunc () {}
  }
}

示例代码

模型

src/app/models/articles.js

module.exports = app => {
  const { STRING, TEXT, INTEGER } = app.$Sequelize

  return app.$model.define('articles', {
    id: {
      type: INTEGER(10).UNSIGNED,
      primaryKey: true,
      autoIncrement: true,
      allowNull: false,
      comment: 'ID'
    },
    title: {
      type: STRING(200),
      allowNull: false,
      comment: '标题'
    },
    content: {
      type: TEXT('long'),
      comment: '内容'
    }
  })
}

服务

src/app/services/articles.js

module.exports = app => {
  return class extends app.$Service {
    constructor () {
      super()

      this.model = app.$models.articles
    }
  }
}

控制器

src/app/controllers/api/v1/public/articles.js

module.exports = app => {
  const service = app.$services.articles

  return class extends app.$Controller {
    async index (ctx, next) {
      ctx.send({
        status: 200,
        data: await service.find({ offset: 0, limit: 10 })
      })
    }
  }
}

路由

src/router/index.js

const router = require('koa-router')()

module.exports = app => {
  router.get('/', app.$controllers.web.home.index)
  router.get('/articles/:id?', app.$controllers.web.articles.index)

  app.use(router.routes()).use(router.allowedMethods())
}

参考

文档

文章

MySQL

Redis

安全

其他参考

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].