-
Notifications
You must be signed in to change notification settings - Fork 6
/
server.js
78 lines (72 loc) · 2 KB
/
server.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
72
73
74
75
76
77
78
var Hapi = require('hapi');
var seneca = require('seneca')();
var server = new Hapi.Server();
var web = server.connection({ port: 4000 });
var api = server.connection({ port: 4040 });
web.route({
method: 'GET',
path: '/{param*}',
handler: {
directory: {
path: 'client'
}
},
config: {
description: 'Web app static content',
notes: 'Set up to respond to web addressing',
tags: ['app', 'checklist', 'spa']
}
});
// Incorporate all needed plugins
seneca.use('user');
seneca.use('auth');
seneca.use('account');
seneca.use('project');
seneca.use('ng-web');
seneca.use('card');
seneca.use('mem-store', {web:{dump:true}});
seneca.use('./server/checklist.js');
seneca.use('./server/entry.js');
var user_pin = seneca.pin({role:'user', cmd:'*'});
var project_pin = seneca.pin({role:'project', cmd:'*'});
var checklist_pin = seneca.pin({role:'checklist', cmd:'*'});
var entry_pin = seneca.pin({role:'entry', cmd:'*'});
api.route({
method: 'GET',
path: '/',
handler: function(request, reply) {
reply('There is always money in the banana stand');
}
});
api.register({
register: require('hapi-seneca'),
options: {
seneca: seneca,
cors: true
}
}, function(err) {
if (err) {
console.error(err);
} else {
user_pin.register({
username: 'a1',
password: 'a1'
}, function(err, out) {
console.log(out.user.accounts[0]);
project_pin.save({name: 'Test project', account: out.user.accounts[0]}, function(err, out) {
checklist_pin.new_checklist({
title:'Test checklist',
project: out.project.id
}, function(err, out) {
entry_pin.add_entry({ checklist:out.checklist.id, title:'test entry'}, function(err, out) {
if (err) return console.error(err);
server.start(function () {
console.log('Server running at: %d and %d', server.connections[0].info.port, server.connections[1].info.port);
});
console.log(out);
});
});
});
});
}
});