-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.coffee
60 lines (43 loc) · 1.57 KB
/
server.coffee
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
################################################################################
#
# Tally examples.
#
# The server for the Tally examples.
#
# Copyright © 2013, Aral Balkan.
# Released under the MIT license. (http://opensource.org/licenses/MIT)
#
################################################################################
express = require 'express'
tally = require './lib/tally-express.coffee'
superagent = require 'superagent'
# Helper: create a route from a route name (e.g., /simple -> /routes/simple.coffee)
createRoute = (routeName) ->
path = if routeName == '/' then 'main' else routeName[1..]
route = require('./routes/' + path + '.coffee').route
app.get routeName, route
#
# Set up Express with Tally as the templating engine.
#
app = express()
app.engine 'html', (require './lib/tally-express.coffee').__express
app.set 'view engine', 'html'
app.set 'views', __dirname + '/views'
app.use express.static('views')
# Index: links to the readme and examples.
createRoute '/'
# Simple template example (with static data)
createRoute '/simple'
# App.net global timeline example.
createRoute '/posts'
# App.net global timeline example.
createRoute '/posts-client-side-updates'
# App.net global timeline example with profiling.
createRoute '/profile'
# A route to render the readme.md file
# createRoute '/readme'
# If /js/tally.js is requested, get it from the lib folder
# (so I don’t have to keep remembering to deploy it to the client)
createRoute '/tally.js'
app.listen 3000
console.log '\nServer running… visit http://localhost:3000/ to play with the Tally examples.\n'