This repository has been archived by the owner on Sep 1, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e3c6191
Showing
5 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,56 @@ | |||
# Derived from https://github.com/assaf/zombie/blob/master/Cakefile, MIT licenced | |||
|
|||
fs = require("fs") | |||
path = require("path") | |||
{spawn, exec} = require("child_process") | |||
stdout = process.stdout | |||
|
|||
# Use executables installed with npm bundle. | |||
process.env["PATH"] = "node_modules/.bin:#{process.env["PATH"]}" | |||
|
|||
# ANSI Terminal Colors. | |||
bold = "\033[0;1m" | |||
red = "\033[0;31m" | |||
green = "\033[0;32m" | |||
reset = "\033[0m" | |||
|
|||
# Log a message with a color. | |||
log = (message, color, explanation) -> | |||
console.log color + message + reset + ' ' + (explanation or '') | |||
|
|||
# Handle error and kill the process. | |||
onerror = (err)-> | |||
if err | |||
process.stdout.write "#{red}#{err.stack}#{reset}\n" | |||
process.exit -1 | |||
|
|||
|
|||
## Building ## | |||
|
|||
build = (callback)-> | |||
log "Compiling CoffeeScript to JavaScript ...", green | |||
exec "rm -rf lib && coffee -c -l -b -o lib src", (err, stdout)-> | |||
callback err | |||
task "build", "Compile CoffeeScript to JavaScript", -> build onerror | |||
|
|||
task "watch", "Continously compile CoffeeScript to JavaScript", -> | |||
cmd = spawn("coffee", ["-cw", "-o", ".", "src"]) | |||
cmd.stdout.on "data", (data)-> process.stdout.write green + data + reset | |||
cmd.on "error", onerror | |||
|
|||
|
|||
clean = (callback)-> | |||
exec "rm -rf lib", callback | |||
task "clean", "Remove temporary files and such", -> clean onerror | |||
|
|||
|
|||
## Testing ## | |||
|
|||
runTests = (callback)-> | |||
log "Running test suite ...", green | |||
exec "nodeunit test", (err, stdout)-> | |||
process.stdout.write stdout | |||
callback err if callback | |||
task "test", "Run all tests", -> | |||
runTests (err)-> | |||
process.stdout.on "drain", -> process.exit -1 if err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
{ | |||
"name": "connect-kyoto", | |||
"description": "Kyoto Tycoon session store for Connect", | |||
"version": "0.1.0", | |||
"homepage": "https://github.com/wezm/connect-kyoto", | |||
"repository": { | |||
"type": "git", | |||
"url": "git://github.com/wezm/connect-kyoto.git" | |||
}, | |||
"author": "Wesley Moore <wes@wezm.net> (http://www.wezm.net/)", | |||
"main": "lib/index.js", | |||
"directories": { | |||
"lib": "lib" | |||
}, | |||
"scripts": { | |||
"test": "cake test" | |||
}, | |||
"dependencies": { | |||
"connect": "~1.0", | |||
"kyoto-client": "~0.3.0" | |||
}, | |||
"devDependencies": { | |||
"coffee-script": "~ 1.0.0", | |||
"nodeunit": "~ 0.5.0" | |||
}, | |||
"engines": { | |||
"node": ">=0.4.3" | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
exports.KyotoStore = require './kyoto-store' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,75 @@ | |||
Store = require('connect').session.Store | |||
kyoto = require 'kyoto-client' | |||
|
|||
### | |||
* Session Store Implementation: | |||
* | |||
* Every session store _must_ implement the following methods | |||
* | |||
* - `.get(sid, callback)` | |||
* - `.set(sid, session, callback)` | |||
* - `.destroy(sid, callback)` | |||
* | |||
* Recommended methods include, but are not limited to: | |||
* | |||
* - `.length(callback)` | |||
* - `.clear(callback)` | |||
### | |||
|
|||
class KyotoStore extends Store | |||
constructor: (options) -> | |||
options = options or {} | |||
unless options.db #and options.host and options.port | |||
throw new Error("db, host and port must be specified") | |||
Store.call this, options | |||
@kyoto = new kyoto.Db(options.db).open(options.host, options.port) | |||
# @db = options.db or 1 | |||
this | |||
|
|||
get: (sid, callback) -> | |||
@kyoto.get sid, (error, value) -> | |||
return callback error if error | |||
return callback undefined, value unless value? | |||
|
|||
try | |||
callback undefined, JSON.parse(value.toString()) | |||
catch exception | |||
console.log exception | |||
callback exception | |||
|
|||
set: (sid, session, callback) -> | |||
# try { | |||
# var maxAge = sess.cookie.maxAge | |||
# , ttl = 'number' == typeof maxAge | |||
# ? maxAge / 1000 | 0 | |||
# : oneDay | |||
# , sess = JSON.stringify(sess); | |||
# this.client.setex(sid, ttl, sess, function(){ | |||
# fn && fn.apply(this, arguments); | |||
# }); | |||
# } catch (err) { | |||
# fn && fn(err); | |||
# } | |||
try | |||
maxAge = session.cookie.maxAge | |||
ttl = maxAge / 1000 | 0 | |||
@kyoto.set sid, JSON.stringify(session), (error) -> | |||
callback() | |||
catch exception | |||
console.log exception | |||
callback exception | |||
|
|||
destroy: (sid, callback) -> | |||
@kyoto.remove sid, (error) -> | |||
# Ignore the error for now. | |||
callback() | |||
|
|||
length: (callback) -> | |||
@kyoto.status (error, info) -> | |||
callback info.count | |||
|
|||
clear: (callback) -> | |||
@kyoto.clear (error) -> | |||
callback error | |||
|
|||
module.exports = KyotoStore |
Empty file.