forked from brianleroux/wtfjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (38 loc) · 1.22 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
require.paths.unshift('./lib')
require.paths.unshift('node_modules')
var Post = require('post').Post
, fs = require('fs')
, path = require('path')
, app = require('config').app
// GET "/" - lists first 5 get("/", Post.paginate);
app.get('/', function(req, res) {
res.render('index.ejs', {locals:Post.page(1)})
})
// GET "/page/2" - lists 5 posts for the page passed
app.get("/page/:n", function(req, res) {
res.render('index.ejs', {locals:Post.page(req.params.n)})
})
// GET "/2010/05/10/title-of-article" - post permalink
app.get("/:y/:m/:d/:title", function(req, res) {
var y = req.params.y
, m = req.params.m
, d = req.params.d
, t = req.params.title
, p = new Post([y,m,d,t].join('-') + '.md')
res.render("post.ejs", {locals:{post:p}})
})
// GET "/rss"
app.get("/rss", function(req, res) {
res.headers['Content-Type'] = 'text/xml; charset=utf-8'
res.send(Post.rss())
})
// FIXME ooooh sync method BaaaaaaAAAAAAaaaad!
// GET "/license" - diplays the WTFPL
app.get('/license', function(req, res) {
res.send(fs.readFileSync(path.join(__dirname, 'LICENSE')))
})
// GET "/about"
app.get("/about", function(req, res) {
res.render('about.ejs')
})
app.listen(process.env.PORT || 4000)