]>
Commit | Line | Data |
---|---|---|
91273161 CJ |
1 | /** |
2 | * term.js - an xterm emulator | |
14248234 | 3 | * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License) |
6cc8b3cd | 4 | * https://github.com/chjj/term.js |
91273161 CJ |
5 | */ |
6 | ||
7 | function term(options) { | |
8 | return new term.Terminal(options); | |
9 | } | |
10 | ||
11 | term.middleware = function(options) { | |
12 | var url = require('url'); | |
13 | return function(req, res, next) { | |
14 | if (url.parse(req.url).pathname !== '/term.js') { | |
15 | return next(); | |
16 | } | |
17 | ||
18 | if (+new Date(req.headers['if-modified-since']) === term.last) { | |
19 | res.statusCode = 304; | |
20 | res.end(); | |
21 | return; | |
22 | } | |
23 | ||
24 | res.writeHead(200, { | |
25 | 'Content-Type': 'application/javascript; charset=utf-8', | |
26 | 'Content-Length': Buffer.byteLength(term.script), | |
27 | 'Last-Modified': term.last | |
28 | }); | |
29 | ||
30 | res.end(term.script); | |
31 | }; | |
32 | }; | |
33 | ||
6e375ccc | 34 | term.path = __dirname + '/../src/term.js'; |
91273161 CJ |
35 | |
36 | term.__defineGetter__('script', function() { | |
37 | if (term._script) return term._script; | |
38 | term.last = +new Date; | |
39 | return term._script = require('fs').readFileSync(term.path, 'utf8'); | |
40 | }); | |
41 | ||
42 | term.__defineGetter__('Terminal', function() { | |
43 | if (term._Terminal) return term._Terminal; | |
6e375ccc | 44 | return term._Terminal = require('../src/term'); |
91273161 CJ |
45 | }); |
46 | ||
47 | /** | |
48 | * Expose | |
49 | */ | |
50 | ||
51 | module.exports = term; |