Installed ueberDB
parent
0c6296c516
commit
68dfff5a21
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* 2011 Peter 'Pita' Martischka
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS-IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var ueberDB = require("ueberDB");
|
||||
var settings = require("./settings");
|
||||
|
||||
//set database settings
|
||||
var db = new ueberDB.database(settings.dbType, settings.dbSettings);
|
||||
|
||||
//set the exported db to null, we will set it in intalize
|
||||
exports.db = null;
|
||||
|
||||
exports.init = function(callback)
|
||||
{
|
||||
//initalize the database async
|
||||
db.init(function(err)
|
||||
{
|
||||
//there was an error while initializing the database, output it and stop
|
||||
if(err)
|
||||
{
|
||||
console.error("ERROR: Problem while initalizing the database");
|
||||
console.error(err.stack ? err.stack : err);
|
||||
process.exit(1);
|
||||
}
|
||||
//everything ok
|
||||
else
|
||||
{
|
||||
exports.db = db;
|
||||
callback(null);
|
||||
}
|
||||
});
|
||||
}
|
|
@ -17,12 +17,25 @@
|
|||
var http = require('http')
|
||||
, url = require('url')
|
||||
, fs = require('fs')
|
||||
, io = require('socket.io')
|
||||
, socketio = require('socket.io')
|
||||
, sys = require('sys')
|
||||
, settings = require('./settings')
|
||||
, server;
|
||||
, db = require('./db')
|
||||
, async = require('async');
|
||||
|
||||
server = http.createServer(function(req, res){
|
||||
async.waterfall([
|
||||
function (callback)
|
||||
{
|
||||
db.init(callback);
|
||||
},
|
||||
function (callback)
|
||||
{
|
||||
db.db.set("a","test");
|
||||
db.db.get("a", function(err,value){
|
||||
console.error(value);
|
||||
})
|
||||
|
||||
var server = http.createServer(function(req, res){
|
||||
var path = url.parse(req.url).pathname;
|
||||
|
||||
if(path.substring(0,"/static".length) == "/static" || path.substring(0,"/p/".length) == "/p/")
|
||||
|
@ -57,10 +70,38 @@ server = http.createServer(function(req, res){
|
|||
send404(res, path);
|
||||
}
|
||||
});
|
||||
server.listen(settings.port);
|
||||
console.log("Server is listening at port 9001");
|
||||
|
||||
function randomPadName() {
|
||||
server.listen(settings.port);
|
||||
console.log("Server is listening at port " + settings.port);
|
||||
|
||||
var io = socketio.listen(server);
|
||||
var messageHandler = require("./MessageHandler");
|
||||
messageHandler.setSocketIO(io);
|
||||
|
||||
io.on('connection', function(client){
|
||||
try{
|
||||
messageHandler.handleConnect(client);
|
||||
}catch(e){errorlog(e);}
|
||||
|
||||
client.on('message', function(message){
|
||||
try{
|
||||
messageHandler.handleMessage(client, message);
|
||||
}catch(e){errorlog(e);}
|
||||
});
|
||||
|
||||
client.on('disconnect', function(){
|
||||
try{
|
||||
messageHandler.handleDisconnect(client);
|
||||
}catch(e){errorlog(e);}
|
||||
});
|
||||
});
|
||||
|
||||
callback(null);
|
||||
}
|
||||
]);
|
||||
|
||||
function randomPadName()
|
||||
{
|
||||
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
|
||||
var string_length = 10;
|
||||
var randomstring = '';
|
||||
|
@ -117,28 +158,6 @@ function requestLog(code, path, desc)
|
|||
console.log(code +", " + path + ", " + desc);
|
||||
}
|
||||
|
||||
var io = io.listen(server);
|
||||
var messageHandler = require("./MessageHandler");
|
||||
messageHandler.setSocketIO(io);
|
||||
|
||||
io.on('connection', function(client){
|
||||
try{
|
||||
messageHandler.handleConnect(client);
|
||||
}catch(e){errorlog(e);}
|
||||
|
||||
client.on('message', function(message){
|
||||
try{
|
||||
messageHandler.handleMessage(client, message);
|
||||
}catch(e){errorlog(e);}
|
||||
});
|
||||
|
||||
client.on('disconnect', function(){
|
||||
try{
|
||||
messageHandler.handleDisconnect(client);
|
||||
}catch(e){errorlog(e);}
|
||||
});
|
||||
});
|
||||
|
||||
function errorlog(e)
|
||||
{
|
||||
var timeStr = new Date().toUTCString() + ": ";
|
||||
|
@ -156,7 +175,3 @@ function errorlog(e)
|
|||
console.error(timeStr + JSON.stringify(e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ var fs = require("fs");
|
|||
|
||||
//default settings
|
||||
exports.port = 9001;
|
||||
exports.dbType = "sqlite";
|
||||
exports.dbSettings = { "filename" : "../var/sqlite.db" };
|
||||
|
||||
//read the settings sync
|
||||
var settingsStr = fs.readFileSync("../settings.json");
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
"author" : "Peter 'Pita' Martischka <petermartischka@googlemail.com>",
|
||||
"dependencies" : {
|
||||
"socket.io" : ">=0.6.17",
|
||||
"ueberDB" : ">=0.0.1"
|
||||
"ueberDB" : ">=0.0.1",
|
||||
"async" : ">=0.1.9"
|
||||
},
|
||||
"version" : "0.0.1",
|
||||
"bin" : {
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
{
|
||||
"port":9001
|
||||
"port" : 9001,
|
||||
"dbType" : "sqlite",
|
||||
"dbSettings" : {
|
||||
"filename" : "../var/sqlite.db"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
sqlite.db
|
Loading…
Reference in New Issue