-
Notifications
You must be signed in to change notification settings - Fork 2
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
Gizeta
committed
Jan 14, 2016
1 parent
6f5280a
commit f5f47f8
Showing
12 changed files
with
490 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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compact": false, | ||
"comments": false, | ||
"presets": ["es2015"], | ||
"plugins": [ | ||
"syntax-async-functions", | ||
"syntax-object-rest-spread", | ||
"transform-object-rest-spread", | ||
"transform-regenerator", | ||
"transform-runtime" | ||
] | ||
} |
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
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
src | ||
node_modules |
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 | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# kcsp | ||
|
||
[![NPM](https://nodei.co/npm/kcsp.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/kcsp/) | ||
|
||
A simple proxy server for KanColle to avoid network problems. |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/node | ||
|
||
var getopt = require('node-getopt'); | ||
var env = require('../lib/env'); | ||
|
||
var cmd = getopt.create([ | ||
['c', 'cache-path=ARG', 'set cache database path'], | ||
['l', 'log-path=ARG', 'set log file path'], | ||
['p', 'path=ARG', 'set base path'], | ||
['v', 'version', 'show version'] | ||
]).bindHelp().parseSystem(); | ||
|
||
if (cmd.options['version']) { | ||
console.log(env.APP_VERSION); | ||
process.exit(); | ||
} | ||
|
||
require('daemon')(); | ||
|
||
var args = []; | ||
if (cmd.options['path']) { | ||
args.push('--path=' + cmd.options['path']); | ||
} | ||
if (cmd.options['cache-path']) { | ||
args.push('--cache-path=' + cmd.options['cache-path']); | ||
} | ||
if (cmd.options['log-path']) { | ||
args.push('--log-path=' + cmd.options['log-path']); | ||
} | ||
|
||
process.title = 'kcsp monitor'; | ||
|
||
var forever = require('forever-monitor'); | ||
|
||
var child = new (forever.Monitor)(__dirname + '/../lib/cli.js', { | ||
args: args | ||
}); | ||
|
||
child.start(); |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "kcsp", | ||
"version": "0.4.0", | ||
"description": "A simple proxy server for KanColle to avoid network problems.", | ||
"bin": { | ||
"kcsp": "./bin/kcsp" | ||
}, | ||
"scripts": { | ||
"compile": "babel -d lib/ src/", | ||
"prepublish": "npm run compile" | ||
}, | ||
"author": "Gizeta", | ||
"license": "GPL-2.0", | ||
"files": [ | ||
"bin", | ||
"lib" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Gizeta/kcsp.git" | ||
}, | ||
"keywords": [ | ||
"kancolle", | ||
"proxy" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/Gizeta/kcsp/issues" | ||
}, | ||
"homepage": "https://github.com/Gizeta/kcsp", | ||
"dependencies": { | ||
"babel-polyfill": "^6.3.14", | ||
"daemon": "^1.1.0", | ||
"forever-monitor": "^1.7.0", | ||
"level": "^1.4.0", | ||
"level-ttl": "^3.1.0", | ||
"node-getopt": "^0.2.3", | ||
"request": "^2.67.0", | ||
"tracer": "^0.8.2" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.4.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.3.13", | ||
"babel-plugin-transform-regenerator": "^6.3.26", | ||
"babel-preset-es2015": "^6.3.13" | ||
} | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import server from './server'; | ||
import config from './config'; | ||
import logger from './logger'; | ||
import 'babel-polyfill'; | ||
|
||
server.listen(config.port); | ||
logger.info('kcsp server started.'); |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import getopt from 'node-getopt'; | ||
|
||
let cmd = getopt.create([ | ||
['b', 'path=ARG', 'set base path'], | ||
['c', 'cache-path=ARG', 'set cache database path'], | ||
['l', 'log-path=ARG', 'set log file path'], | ||
['p', 'port=ARG', 'set web port'] | ||
]).bindHelp().parseSystem(); | ||
|
||
let basePath = cmd.options['path'] || __dirname + '/..'; | ||
let logPath = cmd.options['log-path'] || (basePath + '/log'); | ||
let cachePath = cmd.options['cache-path'] || (basePath + '/cache'); | ||
let port = cmd.options['cache-path'] ? parseInt(cmd.options['cache-path']) : 8099; | ||
|
||
module.exports = { | ||
basePath: basePath, | ||
cachePath: cachePath, | ||
logPath: logPath, | ||
port: port | ||
}; |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import levelup from 'level'; | ||
import ttl from 'level-ttl'; | ||
import config from './config'; | ||
import logger from './logger'; | ||
|
||
let db = levelup(config.cachePath); | ||
db = ttl(db, { | ||
checkFrequency: 2 * 60 * 60 * 1000, | ||
defaultTTL: 30 * 60 * 1000 | ||
}); | ||
|
||
export async function get(key) { | ||
return new Promise((resolve, reject) => { | ||
db.get(key, function(err, value) { | ||
if (err) { | ||
if (err.notFound) { | ||
resolve(); | ||
return; | ||
} | ||
logger.error('database error, %s', err); | ||
reject(err); | ||
return; | ||
} | ||
resolve(value); | ||
}); | ||
}); | ||
} | ||
|
||
export function put(key, value) { | ||
db.put(key, value, function(err) { | ||
if (err) { | ||
logger.error('database error, %s', err); | ||
} | ||
}); | ||
} | ||
|
||
export function del(key) { | ||
db.del(key, function(err) { | ||
if (err) { | ||
logger.error('database error, %s', 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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
APP_VERSION: '0.4.0' | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import tracer from 'tracer'; | ||
import fs from 'fs'; | ||
import config from './config'; | ||
|
||
(function(){ | ||
if (!fs.existsSync(config.logPath)) { | ||
fs.mkdirSync(config.logPath); | ||
} | ||
})(); | ||
|
||
module.exports = tracer.dailyfile({root: config.logPath}); |
Oops, something went wrong.