Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Issue #19296 Remove old XT server.

  • Loading branch information...
commit 7bf724992451286839dcae8b3f03f8ca6457f21c 1 parent 6cbca87
@bendiy bendiy authored
View
55 node-datasource/xt/server/ext/functor.js
@@ -1,55 +0,0 @@
-/*jshint node:true, indent:2, curly:false, eqeqeq:true, immed:true, latedef:true, newcap:true, noarg:true,
-regexp:true, undef:true, strict:true, trailing:true, white:true */
-/*global X:true */
-
-(function () {
- "use strict";
-
- var _ = X._, _path = X.path;
-
- /**
- Functor
-
- @class
- @extends X.Object
- */
- X.Functor = X.Object.extend(/** @lends X.Functor */{
-
- /**
- Initializes functor from handles
- */
- init: function () {
- var handles = this.get("handles");
- if (X.typeOf(handles) !== X.T_ARRAY) handles = [handles];
- X.functors.push({handles: handles, target: this});
- _.each(handles, function (handle) {
- X.functorMap[handle] = this;
- }, this);
- },
-
- handle: function (payload, session) {},
-
- handles: null,
-
- className: "X.Functor"
- });
-
- X.run(function () {
- var path, files;
-
- if (!X.functorsDirectory) return;
-
- path = _path.join(X.basePath, X.functorsDirectory);
-
- X.functors = [];
- X.functorMap = {};
-
- X.log("Loading functors from %@".f(
- X.shorten(path, 3)));
-
- files = X.directoryFiles(path, {extension: ".js", fullPath: true});
- _.each(files, function (file) {
- require(file);
- });
- });
-}());
View
201 node-datasource/xt/server/ext/response.js
@@ -1,201 +0,0 @@
-/*jshint node:true, indent:2, curly:false, eqeqeq:true, immed:true, latedef:true, newcap:true, noarg:true,
-regexp:true, undef:true, strict:true, trailing:true, white:true */
-/*global X:true */
-
-(function () {
- "use strict";
-
- var _ = X._, _url = require("url");
-
- /**
- General purpose response object can deal with WebSockets or HTTP
- and abstracts the details.
-
- @class
- @extends X.Object
- @see X.HTTPResponse
- @see X.SocketResponse
- */
- X.Response = X.Object.extend({
- init: function () {
- if (this.socket) {
- X.mixin(this, X.SocketResponse);
- } else {
- X.mixin(this, X.HTTPResponse);
- }
- this.initMixin();
- }
- });
-
- /**
- Implementation of X.Reponse for HTTP requests
-
- @class
- @see X.Response
- */
- X.HTTPResponse = {
-
- isReady: false,
- isClosed: false,
- isDestroyed: false,
- data: "",
- code: 200,
- payload: null,
-
- initMixin: function () {
- var req, chunk, didChunk;
- chunk = _.bind(this.chunk, this);
- didChunk = _.bind(this.didChunk, this);
- req = this.get("request");
- req.on("data", chunk);
- req.on("end", didChunk);
- },
-
- debug: function (message) {
- X.debug("HTTPResponse debugging: %@".f(message));
- },
-
- chunk: function (chunk) {
- this.data += chunk;
- },
-
- didChunk: function () {
- if (X.typeOf(this.data) === X.T_STRING) this.payload = X.json(this.data);
- else this.payload = this.data;
- this.set("isReady", true);
- },
-
- requestType: function () {
- return this.get("json").requestType;
- }.property(),
-
- json: function () {
- var data = this.get("data");
- return data ? X.json(data) : {requestType:"NO REQUEST TYPE"};
- }.property(),
-
- destroy: function () {
- this.close();
- delete this.request;
- delete this.response;
- this.removeAllListeners();
- this.set("isDestroyed", true);
- },
-
- error: function (message) {
- this.set("code", 400);
- this.write(message).close();
- this.destroy();
- },
-
- method: function () {
- return this.get("request").method;
- }.property(),
-
- close: function () {
- if (this.isDestroyed || this.isClosed) return this;
- this.get("response").end();
- this.set("isClosed", true);
- },
-
- /**
- Returns the URL of the request
-
- @method X.Response.path
- */
- path: function () {
- return _url.parse(this.get("request").url).pathname;
- }.property(),
-
- url: function () {
- return this.get("request").url;
- }.property(),
-
- host: function () {
- return this.get("request").headers.host;
- }.property(),
-
- write: function () {
- var res = this.get("response"),
- args = X.$A(arguments), i = 0;
- for (; i < args.length; ++i) {
- if (X.typeOf(args[i]) !== X.T_STRING) {
- args[i] = X.json(args[i]);
- }
- //X.debug("writing: ", X.typeOf(args[i]), " ", args[i]);
- res.write(args[i]);
- }
- return this;
- },
-
- codeDidChange: function () {
- X.debug("codeDidChange(): ");
- var res = this.get("response"), code = this.get("code");
- res.statusCode = code;
- }.observes("code")
-
- };
-
- /**
- Implementation of X.Reponse for socket requests
-
- @class
- @see X.Response
- */
- X.SocketResponse = {
-
- useSocket: true,
- payload: null,
- store: {},
-
- initMixin: function () {
- this.payload = this.data;
- this.data = this.data.payload;
-
- if (X.typeOf(this.data) === X.T_HASH)
- this.data = X.json(this.data);
-
- this.store = {};
- },
-
- requestType: function () {
- return this.get("path");
- }.property(),
-
- debug: function (message) {
- if (!X.debugging) return;
- this.get("socket").emit("debug", {message: message});
- },
-
- write: function (chunk) {
- X.mixin(this.store, chunk);
- return this;
- },
-
- url: function () {
- return this.get("request").url;
- }.property(),
-
- close: function () {
- this.ack(this.store);
- return this;
- },
-
- error: function (err) {
- //X.warn("X.Response.error(): ", err);
- this.write(X.mixin(err, {isError: true})).close();
- this.destroy();
- },
-
- destroy: function () {
- if (this.isDestroyed) return this;
- this.removeAllListeners();
- delete this.socket;
- delete this.ack;
- this.set("isDestroyed", true);
- }
-
- };
-
-
-}());
View
68 node-datasource/xt/server/ext/route.js
@@ -1,68 +0,0 @@
-/*jshint node:true, indent:2, curly:false, eqeqeq:true, immed:true, latedef:true, newcap:true, noarg:true,
-regexp:true, undef:true, strict:true, trailing:true, white:true */
-/*global X:true */
-
-(function () {
- "use strict";
-
- var _ = X._, _path = X.path;
-
- /**
- A route is a request handler, or maybe the mapping of a path to a handler
-
- @class
- @extends X.Object
- */
- X.Route = X.Object.extend(/** @lends X.Route */{
- /**
- Init.
-
- */
- init: function () {
- //X.debug("X.Route.init(%@)".f(this.get("className")));
- var handles = this.handles, regex, tmp = [];
- regex = /({[A-Za-z0-9]*})/g;
- _.each(handles, function (handle, idx) {
- var match = handle.match(regex), base, route;
- if (match) {
- base = handle.replace(regex, "([A-Za-z0-9]*)").suf("$");
- base = base.escape();
- tmp.push(new RegExp(base));
- }
- });
- if (tmp.length > 0) handles = handles.concat(tmp);
- this.handles = handles;
- },
-
- /**
- Handle.
-
- @type {Function}
- */
- handle: function (xtr) {},
-
- /**
- Array of paths that this handler can deal with.
-
- @type {Array}
- */
- handles: []
- });
-
- X.run(function () {
- var path, files;
-
- if (!X.routesDirectory) return;
-
- path = _path.join(X.basePath, X.routesDirectory);
-
- X.log("Loading routes from %@".f(
- X.shorten(path, 3)));
-
- files = X.directoryFiles(path, {extension: ".js", fullPath: true});
- _.each(files, function (file) {
- require(file);
- });
- });
-
-}());
View
147 node-datasource/xt/server/ext/router.js
@@ -1,147 +0,0 @@
-/*jshint node:true, indent:2, curly:false, eqeqeq:true, immed:true, latedef:true, newcap:true, noarg:true,
-regexp:true, undef:true, strict:true, trailing:true, white:true */
-/*global X:true */
-
-(function () {
- "use strict";
-
- var _ = X._, _path = X.path;
-
- /**
- Sends a request to the appropriate request handler.
-
- @class
- @extends X.Object
- */
- X.Router = X.Object.extend(/** @lends X.Router */{
- /**
- Determines behavior for requests whose routing cannot be determined.
-
- @type {Boolean}
- */
- dropOnNotFound: true,
-
- /**
- Init.
-
-
- */
- init: function () {
- var routes = this.routes, map, mapr;
- map = this.routes = {}, mapr = this.regexRoutes = [];
- //X.debug("X.Router.init(): ", routes);
- // this is ok because it is a one-time nested loop
- // during initialization of router(s) at datasource
- // startup
- _.each(routes, function (route) {
- _.each(route.handles, function (handle) {
- if (X.typeOf(handle) === X.T_STRING) map[handle] = route;
- else mapr.push({expr: handle, route: route});
- });
- });
-
- //X.debug(mapr);
- //X.debug("X.Router.init(): ", routes);
- },
-
- /**
- Routes a request to the appropriate request handler
-
- @param {X.Response} xtr The response object.
- */
- route: function (xtr) {
- var path = xtr.get("path"), regexRoutes = this.regexRoutes || [], match, handler, filter;
-
- //console.log("route(): ", path, Object.keys(this.routes), this.routes[path]);
- //X.debug("X.Router.route(): ", path);
-
- // arbitrary check since some browsers automatically
- // request a favicon.ico
- if (path.match(/\.ico/g)) {
- xtr.error("I don't offer a favicon.ico");
- return true;
- } else if ((handler = this.routes[path]) || (handler = this.routes["*"])) {
- handler.handle(xtr);
- //X.debug("X.Router.route(): returning true for match exact path or *");
- return true;
- } else {
- filter = _.filter(regexRoutes, function (regex) {
- //X.debug("REGEX: ", regex, ", path: ", path);
- var route = regex.route.handle;
- match = regex.expr.exec(path);
- //console.log(match);
- //if ((match = regex.expr.exec(path))) {
- if (match) {
- match = match.slice(1); // remove the inital match of full string
- match.unshift(xtr);
- route.apply(regex.route, match);
- return true;
- } else return false;
- }, this);
- if (filter && filter.length > 0) {
- //X.debug("X.Router.route(): filter was ", filter);
- return true;
- }
- }
- this.drop(xtr);
- //X.debug("returning false");
- return false;
- },
-
- /**
- Creates a response and dispatches it ass soon as the request handler
- is ready.
- */
- handle: function (req, res) {
- var xtr;
- (xtr = X.Response.create({
- request: req,
- response: res
- })).once("isReady", _.bind(this.route, this, xtr));
- },
-
- /**
- Drops request
-
- @param {X.Response} xtr
- */
- drop: function (xtr) {
- if (this.get("dropOnNotFound")) xtr.error("You just have no clue do you?");
- },
-
- /**
- Known routes.
-
- @type {Array}
- */
- routes: [],
-
- /**
- Known regex routes.
-
- @type {Array}
- */
- regexRoutes: [],
-
- className: "X.Router"
- });
-
- X.run(function () {
- var path, files;
-
- if (!X.routersDirectory) return;
-
- path = _path.join(X.basePath, X.routersDirectory);
-
- X.log("Loading routers from %@".f(
- X.shorten(path, 3)));
-
- files = X.directoryFiles(path, {extension: ".js", fullPath: true});
- _.each(files, function (file) {
- require(file);
- });
- });
-
-}());
-
-
View
1  node-datasource/xt/server/package.json
@@ -1 +0,0 @@
-{ "name": "server", "main": "server.js" }
View
207 node-datasource/xt/server/server.js
@@ -1,207 +0,0 @@
-/*jshint node:true, indent:2, curly:false, eqeqeq:true, immed:true, latedef:true, newcap:true, noarg:true,
-regexp:true, undef:true, strict:true, trailing:true, white:true */
-/*global X:true, issue:true */
-
-(function () {
- "use strict";
-
- require("./ext/response");
- require("./ext/route");
- require("./ext/router");
- require('./ext/functor');
-
- var _ = X._, _fs = X.fs, _path = X.path, _https = X.https;
- /**
- The node server.
-
- @class
- @extends X.Object
- */
- X.Server = X.Object.extend(/** @lends X.Server */{
- autoStart: false,
- port: null,
- name: null,
- useWebSocket: false,
- router: null,
- server: null,
- secure: false,
- keyFile: null,
- certFile: null,
- passPhrase: null,
- caFile: null,
- bindAddress: null,
- parseCookies: false,
- isRunning: false,
- /**
- Initializes server
- */
- init: function () {
- var auto = this.get("autoStart"),
- port = this.get("port"),
- name = this.get("name"),
- router = this.get("router"),
- sockets = this.get("useWebSocket");
-
- if (!name) name = this.name = "NONAME%@".f(_.uniqueId("_server"));
- if (!port) {
- issue(X.fatal("cannot create a server with no port %@".f(name)));
- }
- //if (!router && !sockets) issue(X.fatal("cannot create a non-websocket server with no router"));
-
- if (auto) this.start();
-
- X.Server.registerServer(this);
- },
-
- /**
- Returns sockets if they exist
-
- @method X.Server.sockets
- */
- sockets: function () {
- return this._io && this._io.sockets ? this._io.sockets : null;
- }.property(),
-
- /**
- Routes a request.
- */
- route: function (req, res) {
- var router = this.get("router");
- if (router) router.handle.call(router, req, res);
- },
-
- /**
- Synchronously returns the cert file
-
- @method X.Server.cert
- */
- cert: function () {
- var file = this.get("certFile");
- return _fs.readFileSync(_path.join(X.basePath, file));
- }.property(),
-
- key: function () {
- var file = this.get("keyFile");
- return _fs.readFileSync(_path.join(X.basePath, file));
- }.property(),
-
- ca: function () {
- var file = this.get("caFile");
- if (!file) return null;
- if (X.typeOf(file) !== X.T_ARRAY) file = [file];
- return file.map(function (caFile){return _fs.readFileSync(_path.join(X.basePath, caFile))});
- }.property(),
-
- start: function () {
- var port = this.get("port"), useSockets = this.get("useWebSocket"),
- generator = this.get("generator"), server, app = this.server, options = {},
- secure = this.get("secure"), bindAddress = this.get("bindAddress"),
- cookies = this.get("parseCookies");
-
- if (secure) {
- options.key = this.get("key");
- options.cert = this.get("cert");
- if (this.get("passPhrase")) options.passPhrase = this.get("passPhrase");
- options.ca = this.get("ca");
-
- //X.debugging = true;
- //X.debug(options);
- }
-
- // TODO: remove this from a try/catch but test for consequences in fail case...
- // right now it wraps unintended sub-calls
- try {
- if (X.none(app)) {
- //if (secure) app = X.connect(options).use(_.bind(this.route, this));
- //else app = X.connect().use(_.bind(this.route, this));
- //if (secure) app = X.connect(X.https.createServer(options));
- //else app = X.connect();
- app = X.connect();
-
- if (cookies) app.use(X.connect.cookieParser());
- app.use(_.bind(this.route, this));
-
- if (secure) app = _https.createServer(options, app);
- }
-
- app.on("listening", _.bind(function () {this.set("isRunning", true)}, this));
-
- if (bindAddress) server = this.server = app.listen(port, bindAddress);
- else server = this.server = app.listen(port);
-
- if (useSockets) {
- //this._io = require("socket.io").listen(server);
- this._io = require("socket.io").listen(server, X.mixin({
- "log level": 0,
- //"browser client": true,
- "origins": "*:*",
- "transports": [
- "websocket",
- "xhr-polling",
- "jsonp-polling"
- ]
- }, options));
- }
- } catch (err) { issue(X.fatal(err)); }
-
- X.log("Started %@server, %@, listening on port %@".f(secure? "secure ": "", this.get("name"), port));
-
- return this;
- },
- setSocketHandler: function (namespace, event, callback, context) {
- var io = this._io;
- callback = context? _.bind(callback, context): callback;
- io.of(namespace).on(event, function (socket) {
- callback(socket);
- });
- },
- socketsFor: function (namespace) {
- var io = this._io,
- ns = io.namespaces[namespace];
- if (ns && ns.sockets) return ns.sockets;
- },
- close: function () {
- if (this.server) {
- X.log("Server: '%@' shutting down.".f(this.get('name')));
- if (this.get("isRunning")) this.server.close();
- }
- return this;
- },
- className: "X.Server"
- });
-
-
- X.mixin(X.Server, {
-
- activeServers: {},
-
- registerServer: function (server) {
- var name = server.get('name'),
- servers = this.activeServers;
- if (servers[name]) {
- issue(X.warning("Registering server but under unique name " +
- "because a server by that name already existed (%@ => %@)".f(
- name, server.get('uid'))));
- name = server.get('uid');
- }
- this.activeServers[name] = server;
- },
-
- getServer: function (name) {
- return this.activeServers[name];
- },
-
- closeAll: function () {
- X.log("Shutting down all active servers.");
- var servers = this.activeServers,
- names = Object.keys(servers), i, name, server;
- for (i = 0; i < names.length; ++i) {
- name = names[i];
- server = servers[name];
- if (server) server.close();
- }
- }
- });
-
- X.addCleanupTask(_.bind(X.Server.closeAll, X.Server));
-}());
View
1  node-datasource/xt/xt.js
@@ -63,7 +63,6 @@ require('./foundation');
);
if (X.requireDatabase) require("./database");
- if (X.requireServer) require("./server");
X.pid = process.pid;
Please sign in to comment.
Something went wrong with that request. Please try again.