Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

include lib again.

  • Loading branch information...
commit 6ab947821a2af8fe87d589b170f1c66741f9b599 1 parent 6250ba9
@suwanny authored
View
1  .gitignore
@@ -1,3 +1,2 @@
node_modules
-lib
View
12 lib/lib/config.js
@@ -0,0 +1,12 @@
+// Generated by CoffeeScript 1.3.3
+
+global.config = {
+ LOG_LEVEL: "info",
+ LISTEN_PORT: 5985
+};
+
+global._ = require('underscore');
+
+global.FutonServer = require('./futon_server');
+
+global.logger = new (require('./logger'))("redis_futon");
View
102 lib/lib/futon_server.js
@@ -0,0 +1,102 @@
+// Generated by CoffeeScript 1.3.3
+var FutonServer, MainController, express, querystring;
+
+express = require('express');
+
+querystring = require('querystring');
+
+MainController = require('./main_controller');
+
+FutonServer = (function() {
+
+ function FutonServer() {
+ this.app = express.createServer();
+ this.main_controller = new MainController();
+ this.configure(this.app);
+ }
+
+ FutonServer.prototype.configure = function(app) {
+ app.configure(function() {
+ app.use(express.methodOverride());
+ app.use(app.router);
+ app.use(express["static"](__dirname + '/../../www/public'));
+ app.use(express.errorHandler({
+ dumpExceptions: true,
+ showStack: true
+ }));
+ app.set("view options", {
+ layout: false
+ });
+ app.set('views', __dirname + '/../../www/views');
+ app.set('view engine', 'ejs');
+ });
+ app.get('/info', this.process('info', this.main_controller));
+ };
+
+ FutonServer.prototype.start = function() {
+ this.app.listen(config.LISTEN_PORT);
+ return logger.info("Server is listening to " + config.LISTEN_PORT);
+ };
+
+ FutonServer.prototype.process = function(path, handler) {
+ var _this = this;
+ return function(req, res) {
+ var fn_handler;
+ try {
+ fn_handler = function(req, res) {
+ return handler[path](req, res);
+ };
+ return _this.parse_post_body(req, res, fn_handler);
+ } catch (err) {
+ logger.error("process Error", err);
+ return res.json({
+ error: true,
+ reason: 'express error',
+ message: err.message
+ });
+ }
+ };
+ };
+
+ FutonServer.prototype.parse_post_body = function(req, res, callback) {
+ var body_buffer;
+ if (req.method === 'POST') {
+ body_buffer = '';
+ req.on('data', function(data) {
+ return body_buffer += data;
+ });
+ return req.on('end', function() {
+ var content_type;
+ content_type = req.headers['content-type'];
+ logger.debug("[Server] Content-Type: " + content_type);
+ try {
+ req.body = (function() {
+ switch (content_type) {
+ case "application/json":
+ case "json":
+ return JSON.parse(body_buffer);
+ case "application/x-www-form-urlencoded":
+ return querystring.parse(body_buffer);
+ default:
+ return body_buffer;
+ }
+ })();
+ return callback(req, res);
+ } catch (err) {
+ logger.error("[Server] parse_post_body", err);
+ if (err.type === 'unexpected_token') {
+ logger.error("[Server] Illegal JSON String", body_buffer);
+ }
+ throw err;
+ }
+ });
+ } else {
+ return callback(req, res);
+ }
+ };
+
+ return FutonServer;
+
+})();
+
+module.exports = FutonServer;
View
66 lib/lib/logger.js
@@ -0,0 +1,66 @@
+// Generated by CoffeeScript 1.3.3
+var Logger, util, winston;
+
+util = require('util');
+
+winston = require('winston');
+
+Logger = (function() {
+
+ function Logger(name, log_level) {
+ var ConsoleTransport, FileTransport;
+ this.log_level = log_level != null ? log_level : "info";
+ ConsoleTransport = new winston.transports.Console({
+ colorize: 'true',
+ level: config.LOG_LEVEL
+ });
+ FileTransport = new winston.transports.File({
+ filename: "" + name + ".log"
+ });
+ this.logger = new winston.Logger({
+ transports: [ConsoleTransport]
+ });
+ }
+
+ Logger.prototype.get_timestr = function() {
+ var now, timestr;
+ now = new Date();
+ timestr = now.getFullYear() + "/" + (now.getMonth() + 1) + "/" + now.getDate();
+ timestr += " " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
+ timestr += "." + now.getMilliseconds();
+ return timestr;
+ };
+
+ Logger.prototype.info = function(msg, obj) {
+ if (obj != null) {
+ msg += ": " + util.inspect(obj);
+ }
+ return this.logger.info(" " + this.get_timestr() + "\t" + msg);
+ };
+
+ Logger.prototype.error = function(msg, obj) {
+ if (obj != null) {
+ msg += ": " + util.inspect(obj);
+ }
+ return this.logger.error(this.get_timestr() + "\t" + msg);
+ };
+
+ Logger.prototype.debug = function(msg, obj) {
+ if (this.log_level !== 'debug') {
+ return;
+ }
+ if (obj != null) {
+ msg += ": " + util.inspect(obj);
+ }
+ return this.logger.debug(this.get_timestr() + "\t" + msg);
+ };
+
+ Logger.prototype.etrace = function(err) {
+ return this.error(err.stack);
+ };
+
+ return Logger;
+
+})();
+
+module.exports = Logger;
View
26 lib/lib/main_controller.js
@@ -0,0 +1,26 @@
+// Generated by CoffeeScript 1.3.3
+var MainController, RedisInterface;
+
+RedisInterface = require('./redis_interface');
+
+MainController = (function() {
+
+ function MainController() {
+ this.redis = new RedisInterface();
+ }
+
+ MainController.prototype.info = function(req, res) {
+ return this.redis.info(function(err, resp) {
+ return res.json({
+ app: "Redis Futon",
+ version: "0.0.1",
+ server_info: resp
+ });
+ });
+ };
+
+ return MainController;
+
+})();
+
+module.exports = MainController;
View
27 lib/lib/redis_interface.js
@@ -0,0 +1,27 @@
+// Generated by CoffeeScript 1.3.3
+var RedisInterface, redis;
+
+redis = require("redis");
+
+RedisInterface = (function() {
+
+ function RedisInterface(host, port) {
+ this.host = host != null ? host : 'localhost';
+ this.port = port != null ? port : 6379;
+ this.client = redis.createClient(this.port, this.host);
+ this.client.on("error", function(err) {
+ return logger.error("Redis Error", err);
+ });
+ }
+
+ RedisInterface.prototype.info = function(callback) {
+ return this.client.info(function(err, resp) {
+ return callback(err, resp);
+ });
+ };
+
+ return RedisInterface;
+
+})();
+
+module.exports = RedisInterface;
View
7 lib/main.js
@@ -0,0 +1,7 @@
+// Generated by CoffeeScript 1.3.3
+
+require('./lib/config');
+
+logger.info("RedisFuton start...");
+
+new FutonServer().start();
Please sign in to comment.
Something went wrong with that request. Please try again.