npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

annotatify

v0.0.3

Published

Annotatify ==========

Downloads

7

Readme

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;