-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.coffee
53 lines (42 loc) · 1.73 KB
/
app.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
## App Setup
express = require("express")
mongoose = require("mongoose")
app = express()
serverPort = process.env.PORT or 3100
mongoDBUrl = process.env.MONGOHQ_URL or 'mongodb://localhost/alfred_notes_dev'
passport = require('passport')
## Connect to Mongo
mongoose.connect(mongoDBUrl)
## Configure App
app.configure ->
app.set('views', __dirname + '/views')
app.set('view engine', 'jade')
app.use(express.logger('dev'))
app.use(express.cookieParser())
app.use(express.bodyParser())
app.use(express.methodOverride())
app.use(express.session({ secret: 'keyboard cat' }))
app.use(passport.initialize())
app.use(passport.session())
app.use(app.router)
## Load Controllers
note = require('./controllers/notes_controller')
session = require('./controllers/sessions_controller')
registration = require('./controllers/registrations_controller')
## Load Helpers
checkAuth = require('./helpers/authentication_helper')
require("./helpers/passport_helper")
## Define Routes
app.get '/', (req, res) -> res.render 'index', { user: req.user }
app.get '/login', session.new
app.post '/login', passport.authenticate('local'), session.create
app.get '/logout', session.destroy
app.get '/register', registration.new
app.post '/register', registration.create
app.get '/api/notes', passport.authenticate('bearer', { session: false }), note.index
app.get '/api/notes/today', passport.authenticate('bearer', { session: false }), note.today
app.get '/api/notes/:id', passport.authenticate('bearer', { session: false }), note.show
app.post '/api/notes', passport.authenticate('bearer', { session: false }), note.create
## Start Server
app.listen serverPort, ->
console.log "Server listening on port #{serverPort}..."