]> git.proxmox.com Git - mirror_xterm.js.git/blob - lib/index.js
4a18fc2d624e11ec5f46c71355ad2f29aab328dc
[mirror_xterm.js.git] / lib / index.js
1 /**
2 * term.js - an xterm emulator
3 * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
4 * https://github.com/chjj/term.js
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
14 options = options || {};
15 options.path = options.path || '/term.js';
16
17 return function(req, res, next) {
18 if (url.parse(req.url).pathname !== options.path) {
19 return next();
20 }
21
22 if (+new Date(req.headers['if-modified-since']) === term.last) {
23 res.statusCode = 304;
24 res.end();
25 return;
26 }
27
28 res.writeHead(200, {
29 'Content-Type': 'application/javascript; charset=utf-8',
30 'Content-Length': Buffer.byteLength(term.script),
31 'Last-Modified': term.last
32 });
33
34 res.end(term.script);
35 };
36 };
37
38 term.path = __dirname + '/../src/term.js';
39
40 term.__defineGetter__('script', function() {
41 if (term._script) return term._script;
42 term.last = +new Date;
43 return term._script = require('fs').readFileSync(term.path, 'utf8');
44 });
45
46 term.__defineGetter__('Terminal', function() {
47 if (term._Terminal) return term._Terminal;
48 return term._Terminal = require('../src/term');
49 });
50
51 /**
52 * Expose
53 */
54
55 module.exports = term;