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

rebas

v0.4.1

Published

Node runtime for Saber

Downloads

9

Readme

Rebas

NPM version Build Status License EFE Mobile Team

Node runtime for Saber,base on Express

Saber 的 node 运行环境,让您在享受 SPA 高內聚、低耦合开发方式的同时拥有优秀的首屏呈现速度与良好的 SEO 。

How

Rebas 使首屏渲染由服务器端完成,极大地降低了 SPA 首屏的白屏时间并解决了 SEO 问题。借助于 node ,服务器端的渲染逻辑不用额外开发,只需要对现有的 Saber 应用进行小幅修改就能让已有的逻辑同时运行在客户端与服务器端。

Saber 所有的基础组件都进行了同构升级,确保能同时运行在客户端与服务器端。对于业务开发只需聚焦业务逻辑,不用特别关注运行平台,剩下的一切就交给 Saber 与 Rebas 吧~

Usage

/**
 * @file app.js 应用启动脚本
 */
var app = require('rebas');

// 加载路由配置
app.load(require('./lib/config'));

// 启动服务
app.start();
$ node app.js

更多详情请参考 Getting start ,从零开始快速构建同构应用

API

Methods

start(port, options)

启动服务

  • port {number=} 端口号,默认为 8000
  • options {Object=} 配置项
    • template {string=} 公共模版
    • templateConfig {Object=} 模版引擎配置信息,rebas 使用强复用、灵活、高性能的 etpl 模版引擎,具体配置请参考 etpl 配置项
    • templateData {Object=} 全局模版数据
    • indexFile {string=} 主页面模版文件路径,默认为根目录下的 index.html
    • Presenter {Function=} 自定义 Presenter 基类
    • View {Function=} 自定义 View 基类
    • Model {Function=} 自定义 Model 基类

rebassaber-mm 提供 MVP 的实现,PresenterViewModel 相关的配置与 API 请参考 saber-mm 的说明文档

load(routes)

加载路由配置

  • routes {Object|Array.<Object>} 路由配置信息,必须包含以下两个必填字段:
    • path {string|RegExp} 路径,必须是以 / 开头的有效路径字符串或者正则表达式,字符串可以包含以:开头的参数化路径,例如:/detail/:id
    • action {string|Object} Presenter 配置信息,如果是字符串则表示对应文件的路径(为啥叫action而不是presenter,嗯... 历史原因...)

get(name)

获取存储在 配置文件夹 下的 JSON 配置信息,配置文件夹 的默认路径为 config

  • name {string} 配置文件名称,不包含 .json 后缀名
  • return {*} 配置信息

例如需要获取 config/app.json 文件中的配置信息可以通过如下方式获得:

var app = require('rebas');

// 获取 `config/app.json` 中的配置信息
app.get('app');

可以通过添加应用启动的参数来修改默认的 配置文件夹 路径,例如:

$ node app.js config-dev

此时通过 get 获取的配置信息就来源于 config-dev 文件夹,可以通过此种方式在多种不同环境、不同配置下自由切换

before(middleware)

添加在执行页面逻辑前执行的中间件

after(middleware)

添加在页面逻辑执行完成后执行的中间件

  • middleware {Function} 中间件

use(plugin)

使用插件

  • plugin {Object} 插件对象,插件必须包含 rebas 方法用于初始化,具体的方法说明如下:
    • rebas {function(app, ...*)} 插件初始化方法,第一个参数为 rebas 实例,其余参数为调用 use 方法时传入的剩余参数

setSyncData(name, value)

设置需要前后端同步的数据,设置后前端的运行框架 saber-firework 可以通过其 API 获取到对应的数据

  • name {string} 数据名称
  • value {*} 数据值,建议为 numberstring 类型,或者其它任何可以被 JSON.stringify 方法序列化的数据类型

Config

以下所有的配置信息都是以 JSON 文件的形式存储在 配置文件夹 下,配置文件夹 的默认路径为 config

log

日志配置文件 log.jsonrebas 使用 log4js-node 提供日志服务,相关配置信息更详细的说明请参考 log4js-node 的配置说明,默认的配置信息如下:

{
    // 是否将日志输出到标准输出(stdout)
    console: false,
    // 日志等级
    level: 'INFO',
    // 日志类型,默认为按时间分割的日志文件
    type: 'dateFile',
    // 日志默认存储在 `log` 目录下,名为 `rebas.log`
    filename: 'log/rebas.log',
    // 日志以小时级别切分
    patter: '-MM-dd-hh',
    alwaysIncludePattern: false,
    // 日志输出格式
    layout: {
        type: 'pattern',
        pattern: '[%d] [%x{pid}] [%p] - %m',
        tokens: {
            pid: process.pid
        }
    }
}