-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First draft of api command line tool
- v10.0.0
- v10.0.0-next.1
- v10
- v9.0.5
- v9.0.5-next.1
- v9.0.4
- v9.0.4-next.5
- v9.0.4-next.4
- v9.0.4-next.3
- v9.0.4-next.2
- v9.0.4-next.1
- v9.0.3
- v9.0.3-next.1
- v9.0.2
- v9.0.2-next.2
- v9.0.2-next.1
- v9.0.1
- v9.0.1-next.2
- v9.0.1-next.1
- v9.0.0
- v9.0.0-next.36
- v9.0.0-next.35
- v9.0.0-next.34
- v9.0.0-next.33
- v9.0.0-next.32
- v9.0.0-next.31
- v9.0.0-next.30
- v9.0.0-next.29
- v9.0.0-next.28
- v9.0.0-next.27
- v9.0.0-next.26
- v9.0.0-next.25
- v9.0.0-next.24
- v9.0.0-next.23
- v9.0.0-next.22
- v9.0.0-next.21
- v9.0.0-next.20
- v9.0.0-next.19
- v9.0.0-next.18
- v9.0.0-next.17
- v9.0.0-next.16
- v9.0.0-next.15
- v9.0.0-next.14
- v9.0.0-next.13
- v9.0.0-next.12
- v9.0.0-next.11
- v9.0.0-next.10
- v9.0.0-next.9
- v9.0.0-next.8
- v9.0.0-next.7
- v9.0.0-next.6
- v9.0.0-next.5
- v9.0.0-next.4
- v9.0.0-next.3
- v9.0.0-next.2
- v9.0.0-next.1
- v8.7.0-next.3
- v8.7.0-next.2
- v8.7.0-next.1
- v8.6.6
- v8.6.6-next.1
- v8.6.5
- v8.6.5-next.7
- v8.6.5-next.6
- v8.6.5-next.5
- v8.6.5-next.4
- v8.6.5-next.3
- v8.6.5-next.2
- v8.6.5-next.1
- v8.6.4
- v8.6.4-next.3
- v8.6.4-next.2
- v8.6.4-next.1
- v8.6.3
- v8.6.3-next.1
- v8.6.2
- v8.6.2-next.4
- v8.6.2-next.3
- v8.6.2-next.2
- v8.6.2-next.1
- v8.6.1
- v8.6.1-next.1
- v8.6.0
- v8.6.0-next.17
- v8.6.0-next.16
- v8.6.0-next.15
- v8.6.0-next.14
- v8.6.0-next.13
- v8.6.0-next.12
- v8.6.0-next.11
- v8.6.0-next.10
- v8.6.0-next.9
- v8.6.0-next.8
- v8.6.0-next.7
- v8.6.0-next.6
- v8.6.0-next.5
- v8.6.0-next.4
- v8.6.0-next.3
- v8.6.0-next.2
- v8.6.0-next.1
- v8.5.0
- v8.4.0
- v8.3.1
- v8.3.1-beta.0
- v8.3.0
- v8.3.0-beta.0
- v8.2.1
- v8.2.0
- v8.1.1
- v8.1.0
- v8.0.4
- v8.0.4-beta.0
- v8.0.3
- v8.0.2
- v8.0.1
- v8.0.0
- v8.0.0-beta.9
- v8.0.0-beta.8
- v8.0.0-beta.7
- v8.0.0-beta.6
- v8.0.0-beta.5
- v8.0.0-beta.4
- v8
- v7.5.0
- v3.4.2
- v3.4.1
- v3.4.0
- v3.3.0
- v3.2.0
- v3.1.0
- v3.0.2
- v3.0.0
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.0
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.0.0
- kanad-test-git-ref-do-not-use
- 10.0.0
- 10.0.0-next.1
- 9.0.5
- 9.0.5-next.1
- 9.0.4
- 9.0.4-next.5
- 9.0.4-next.4
- 9.0.4-next.3
- 9.0.4-next.2
- 9.0.4-next.1
- 9.0.3
- 9.0.3-next.1
- 9.0.2
- 9.0.2-next.2
- 9.0.2-next.1
- 9.0.1
- 9.0.1-next.2
- 9.0.1-next.1
- 9.0.0
- 9.0.0-next.36
- 9.0.0-next.35
- 9.0.0-next.34
- 9.0.0-next.33
- 9.0.0-next.32
- 9.0.0-next.31
- 9.0.0-next.30
- 9.0.0-next.29
- 9.0.0-next.28
- 9.0.0-next.27
- 9.0.0-next.26
- 9.0.0-next.25
- 9.0.0-next.24
- 9.0.0-next.23
- 9.0.0-next.22
- 9.0.0-next.21
- 9.0.0-next.20
- 9.0.0-next.19
- 9.0.0-next.18
- 9.0.0-next.17
- 9.0.0-next.16
- 9.0.0-next.15
- 9.0.0-next.14
- 9.0.0-next.13
- 9.0.0-next.12
- 9.0.0-next.11
- 9.0.0-next.10
- 9.0.0-next.9
- 9.0.0-next.8
- 9.0.0-next.7
- 9.0.0-next.6
- 9.0.0-next.5
- 9.0.0-next.4
- 9.0.0-next.3
- 9.0.0-next.2
- 9.0.0-next.1
- 8.7.0-next.3
- 8.7.0-next.2
- 8.7.0-next.1
- 8.6.6
- 8.6.6-next.1
- 8.6.5
- 8.6.5-next.7
- 8.6.5-next.6
- 8.6.5-next.5
- 8.6.5-next.4
- 8.6.5-next.3
- 8.6.5-next.2
- 8.6.5-next.1
- 8.6.4
- 8.6.4-next.3
- 8.6.4-next.2
- 8.6.4-next.1
- 8.6.3
- 8.6.3-next.1
- 8.6.2
- 8.6.2-next.4
- 8.6.2-next.3
- 8.6.2-next.2
- 8.6.2-next.1
- 8.6.1
- 8.6.1-next.1
- 8.6.0
- 8.6.0-next.17
- 8.6.0-next.16
- 8.6.0-next.15
- 8.6.0-next.14
- 8.6.0-next.13
- 8.6.0-next.12
- 8.6.0-next.11
- 8.6.0-next.10
- 8.6.0-next.9
- 8.6.0-next.8
- 8.6.0-next.7
- 8.6.0-next.6
- 8.6.0-next.5
- 8.6.0-next.4
- 8.6.0-next.3
- 8.6.0-next.2
- 8.6.0-next.1
- 8.5.0
- 8.4.0
- 8.3.1
- 8.3.1-beta.0
- 8.3.0
- 8.3.0-beta.0
- 8.2.1
- 8.2.0
- 8.1.1
- 8.1.0
- 8.0.4
- 8.0.4-beta.0
- 8.0.3
- 8.0.2
- 8.0.1
- 8.0.0
- 8.0.0-beta.9
- 8.0.0-beta.8
- 8.0.0-beta.7
- 8.0.0-beta.6
- 8.0.0-beta.5
- 8.0.0-beta.4
- 8.0.0-beta.3
- 8.0.0-beta.2
- 8.0.0-beta.1
- 7.5.0
- 7.4.0
- 7.3.0
- 7.2.2
- 7.2.1
- 7.2.0
- 7.1.1
- 7.1.0
- 7.0.3
- 7.0.2
- 7.0.1
- 7.0.0
- 6.5.0
- 6.4.0
- 6.3.2
- 6.3.1
- 6.3.0
- 6.2.1
- 6.2.0
- 6.1.3
- 6.1.2
- 6.1.1
- 6.1.0
- 6.0.1
- 6.0.0
- 5.2.0
- 5.1.4
- 5.1.3
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.0
- 4.0.0
- 3.8.2
- 3.8.1
- 3.8.0
- 3.7.16
- 3.7.15
- 3.7.14
- 3.7.13
- 3.7.12
- 3.7.11
- 3.7.10
- 3.7.9
- 3.7.8
- 3.7.7
- 3.7.6
- 3.7.5
- 3.7.4
- 3.7.3
- 3.7.2
- 3.7.1
- 3.7.0
- 3.6.2
- 3.6.1
- 3.5.0
- 3.4.9
- 3.4.8
- 3.4.7
Showing
2 changed files
with
82 additions
and
2 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,71 @@ | ||
#!/usr/bin/env node | ||
|
||
var confdir = require('confdir'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var ejs = require('ejs'); | ||
|
||
function die(log, err) { | ||
// ignore errors when closing log file | ||
try { | ||
log.closeSync(log); | ||
} catch (err) {} | ||
|
||
throw err; | ||
} | ||
|
||
confdir(process.cwd(), 'conf', function (err, confdir) { | ||
if (err) | ||
throw err; | ||
|
||
fs.readFile(path.resolve(confdir, 'api.json'), 'uft8', function (err, conf) { | ||
conf = JSON.parse(conf); | ||
|
||
conf.root = path.resolve(confdir, '..'); | ||
|
||
var log = fs.createWriteStream(path.resolve(conf.root, conf.logFile), | ||
{ flags: 'w' }); | ||
var app = new require('api')(conf.protocol).Server(); | ||
|
||
// error handling | ||
app.error = function error(code, req, resp) { | ||
resp.writeHead(code, { 'Content-Type': 'text/html' }); | ||
fs.readFile(path.resolve(conf.root, conf.directories.templates, | ||
code+'.tpl'), 'uft8', function (err, tpl) { | ||
if (err) | ||
die(err); | ||
|
||
resp.end(ejs.render(tpl, { locals: { code: code, request: req } })); | ||
log.write('error: '+code+' '+req.url+'\n'); | ||
}); | ||
}); | ||
|
||
// for every registered module | ||
conf.modules.forEach(function (mod) { | ||
var module = require(path.resolve(conf.root, conf.directories.modules, | ||
mod+'.js') | ||
|
||
// read module specific configuration file | ||
fs.readFile(path.resolve(confdir, mod+'.json'), 'utf8', | ||
function (err, data) { | ||
if (err) | ||
die(err); | ||
|
||
var modConf = JSON.parse(data); | ||
|
||
// hook module into app | ||
module(app, log, modConf, conf); | ||
console.log('Module '+mod+' up and running.'); | ||
}); | ||
}); | ||
|
||
app.listen(conf.socket.path, function () { | ||
fs.chmod(conf.socket.path, conf.socket.permissions, function (err) { | ||
if (err) | ||
die(err); | ||
|
||
console.log('Server listening on '+socket+'.'); | ||
}); | ||
}); | ||
}); | ||
}); |
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