Socket
Socket
Sign inDemoInstall

annotatify

Package Overview
Dependencies
9
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    annotatify

Annotatify ==========


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Annotatify

特性

  • 基于express框架,可以快速入门;
  • 多项目部署、项目分层管理;
  • 使用 annotation 注释模式的路由;
  • 使用 annotation 注入 service (中间件);
  • 使用swig模板作为默认模板引擎;

安装使用

使用npm安装

npm install annotatify

使用 yarn 安装

yarn add mvcify

快速开始

项目默认目录结构如下:

project
  |
  |- apps                             # 应用目录
  |   |- front-end                    # 网站前端
  |   |   |- routes                   # 控制器
  |   |   |   |- index.js             # - index路由
  |   |   |   |- user.js              # - user路由
  |   |   |   `- ...
  |   |   |- services                 # 中间件目录
  |   |   |- assets                   # 静态资源目录
  |   |   |- views                    # 视图目录
  |   |   |- config.js                # 配置
  |   |   `- ...
  |   `- ...
  |- assets
  |- node_modules
  |- services
  |- config.js
  |- app.js
  |- package.json
  `- ...

应用入口文件

四行代码轻松启动你的web应用。

// app.js
const {Annotatify} = require('../lib/index');
const app = new Annotatify(__dirname);
app.setup({'front-end': '/'});
app.express.listen(8080);

应用于路由类上的annotation

程序定义了一些列的指令,作用于控制器的annotation内,轻松实现路由注册,这样 方便开发、路由与方法绑定及查询,具体指令有:

  • get('/path')
  • post('/path')
  • put('/path')
  • patch('/path')
  • delete('/path')
  • head('/path')
  • options('/path')
  • route(["method1","method2"], path="/path")

另外,annotation还支持使用下列指令注册中间件:

  • before("services目录下的中间件文件名")
  • after("services目录下的中间件文件名")

可以多次调用,表示注册多个service 值得注意的是:前一个指令依赖后一个指令是否调用next方法

HTTP方法指令优先级高于route指令,也就是说如果存在HTTP方法指令,则route中对应的的方法无效

// index.js
/**
 * 这里的route时必须的
 *
 * @route("/");
 * @before("serviceName");
 * @before("serviceName2");
 * @after("serviceName")
 */
class IndexRouter {
  constructor(app) {
    this.app = app;
  }

  /**
   * 通过before指令注册的service会在该方法前被执行;
   * 该方法执行了next,才会执行通过after注册的service
   *
   * @get("/");
   * @before("serviceName");
   * @after("serviceName")
   */
  index (req, res, next) {
    console.log(__filename);

    res.render('index', {
      title: 'Mvcify',
      message: 'Hello world!'
    });
  }

  /**
   * route指令中由GET、POST、DELETE、UEF四个方法,其中UEF是不被支持的;
   * 另外,又使用了 get、post指令,route中的GET、POST方法则无效了。
   *
   * @route(["GET", 'post', "Delete", 'UEF']);
   * @get("/oo");
   * @post("/ii");
   */
  about(req, res) {
    res.send('sdnjcjkd');
  }
}

module.exports = IndexRouter;

Keywords

FAQs

Last updated on 22 Jun 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc