forked from wenzowski/derby-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (62 loc) · 2.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require('coffee-script/register');
var http = require('http');
var derby = require('derby');
var express = require('./server');
var chalk = require('chalk');
var path = require('path');
// obj:
// - apps
// Array of apps to include
// - middleware
// Additional Middleware to be added. Maybe used for routes
// - schemas (optional)
// Object - E.g.
// {
// schemas: {
// products: {
// properties: {
// name: {type: 'string', minLength: 6},
// price: {type: 'integer', minimum: 0}
// },
// required: ['name']
// }
// }
// }
// - config (optional)
// Object - default config options
// - publicDir (optional)
// XXX should the be moved to config?
// path to public directory.
// - loginConfig (optional)
// XXX should the be moved to config?
// config for authentication
// - errorMiddleware (optional)
// function - custom middleware for handling errors
// callback:
// TODO: solidify API
// - function - (err, store, config, expressApp, upgrade)
function run(obj, callback) {
derby.run(function(){
var config = require('./config')(obj.config);
var store = require('./store')(derby, obj.schemas, config);
var port = config.get('port');
var ip = config.get('ip');
var middleware = obj.middleware || [];
// Defaults to the root/public of application
var publicDir = obj.publicDir || process.cwd() + '/public';
express(config, store, obj.apps, middleware, publicDir, obj.loginConfig, obj.errorMiddleware, function(expressApp, upgrade){
var server = http.createServer(expressApp);
server.on('upgrade', upgrade);
server.listen(port, function() {
console.log('%d listening. Go to: http://localhost:%d/', process.pid, port);
});
obj.apps.forEach(function(app){
app.writeScripts(store.store, publicDir, {extensions: ['.coffee']}, function(){
console.log('Bundle created:', chalk.yellow(app.name));
});
});
callback(null, store, config, expressApp, upgrade)
});
});
}
exports.run = run;