用于 Node.js 和浏览器的框架组件
var flatiron = require('flatiron'), app = flatiron.app;
app.use(flatiron.plugins.http);
app.router.get('/', function () { this.res.writeHead(200, { 'Content-Type': 'text/plain' }); this.res.end('Hello world!\n'); });
app.start(8080);
# HTTPS 服务器示例:js
var flatiron = require('flatiron'),
app = flatiron.app;
app.use(flatiron.plugins.http, { https: { cert: 'path/to/cert.pem', key: 'path/to/key.pem', ca: 'path/to/ca.pem' } });
app.router.get('/', function () { this.res.writeHead(200, { 'Content-Type': 'text/plain' }); this.res.end('Hello world!\n'); });
app.start(8080);
# CLI 应用示例:js
// example.js
var flatiron = require('flatiron'), app = flatiron.app;
app.use(flatiron.plugins.cli, { dir: __dirname, usage: [ 'This is a basic flatiron cli application example!', '', 'hello - say hello to somebody.' ] });
app.cmd('hello', function () { app.prompt.get('name', function (err, result) { app.log.info('hello '+result.name+'!'); }) })
app.start();
## 运行它:
% node example.js hello
prompt: name: world
info: hello world!
## 安装 # NPM (Node Package Manager) 安装
curl http://npmjs.org/install.sh | sh
# Flatiron 安装
[sudo] npm install flatiron
# Union 安装 (对于 `flatiron.plugins.http` 所需)
npm install union
# 使用: ## 使用 `flatiron.app`: `flatiron.app` 是一个 [broadway 注入容器](https://github.com/flatiron/broadway)。简要来说,它的作用是允许插件直接修改 `app` 对象:js
var flatiron = require('flatiron'),
app = flatiron.app;
var hello = { attach: function (options) { this.hello = options.message || 'Why hello!'; } };
app.use(hello, { message: "Hi! How are you?" });
// Will print, "Hi! How are you?" console.log(app.hello);
平铁中的几乎所有附加功能都来自 Broadway 插件,例如 `flatiron.plugins.http` 和 `flatiron.plugins.暂无开放 Issues,或尚未同步最近议题。