-
Notifications
You must be signed in to change notification settings - Fork 8
/
sample.js
68 lines (64 loc) · 2.06 KB
/
sample.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
var appy = require(__dirname + '/appy.js');
appy.bootstrap({
// Useful for testing appy. For now just supports
// a predeclared set of users. Later this ought to offer
// the password hash npm module + mongodb
auth: {
strategy: 'local',
options: {
users: {
admin: {
username: 'admin',
password: 'demo'
}
}
}
},
// More useful in practice
// auth: {
// strategy: 'twitter',
// options: {
// consumerKey: 'xxxx',
// consumerSecret: 'xxxx',
// callbackURL: 'http://my.example.com:3000/twitter-auth'
// }
// },
static: __dirname + '/sample-public',
// Lock the /new prefix to require login. You can lock
// an array of prefixes if you wish.
// Prefixes must be followed by / or . or
// be matched exactly. To lock everything except the
// login mechanism itself, use locked: true
locked: '/new',
// If you're using locked: true you can make exceptions here
// unlocked: [ '/welcome' ]
sessionSecret: 'whatever',
// Redirects to this host if accessed by another name
// (canonicalization). This is pretty hard to undo once
// the browser gets the redirect, so use it in production only
// host: 'my.example.com:3000',
db: {
// host: 'localhost'
// port: 27017,
name: 'example',
collections: [ 'posts' ]
// If I need indexes I specify that collection in more detail:
// [ { name: 'posts', index: { fields: { { title: 1 } }, unique: true } } ]
// Or more than one index:
// [ { name: 'posts', indexes: [ { fields: { { title: 1 } } }, ... ] } ]
},
ready: function(app, db) {
app.get('/', function(req, res) {
appy.posts.find().sort({created: -1}).toArray(function(err, posts) {
res.send('messages: ' + posts.map(function(post) { return post.message; }).join());
});
});
app.get('/new/:message', function(req, res) {
var post = { 'message': req.params.message, 'createdAt': new Date() };
appy.posts.insert(post, function(err) {
res.send('added');
});
});
appy.listen();
}
});