forked from akshell/guestbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
51 lines (41 loc) · 1.01 KB
/
main.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
// (c) 2011 by Anton Korenyushkin
require('ak').setup();
init = function () {
rv.Entry.create(
{
id: 'unique serial',
author: 'string',
title: 'string',
message: 'string'
});
};
var IndexHandler = Handler.subclass(
{
get: function (request) {
return render(
'index.html', {entries: rv.Entry.all().get({by: '-id'})});
},
post: function (request) {
if (!request.post.author ||
!request.post.title ||
!request.post.message)
throw Failure('All fields are required');
rv.Entry.insert(
{
author: request.post.author,
title: request.post.title,
message: request.post.message
});
return redirect('/');
}
});
var EntryHandler = Handler.subclass(
{
get: function (request, id) {
return render(
'entry.html', {entry: rv.Entry.where({id: id}).getOne()});
}
});
exports.root = new URLMap(
IndexHandler, 'index',
[/\d+/, EntryHandler, 'entry']);