-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.coffee
58 lines (48 loc) · 1.58 KB
/
index.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
express = require 'express'
bodyParser = require 'body-parser'
cookieParser = require 'cookie-parser'
session = require 'express-session'
passport = require 'passport'
TumblrStrategy = require('passport-tumblr').Strategy
coffee = require 'coffee-middleware'
stylus = require('stylus').middleware
tumblr = require './lib/tumblr'
app = express()
app.set 'views', "#{__dirname}/views"
app.set 'view engine', 'jade'
app.use bodyParser()
app.use cookieParser()
app.use session
secret: 'secret'
key: 'sid'
app.use passport.initialize()
app.use passport.session()
app.use stylus
src: "#{__dirname}/public"
app.use coffee
src: "#{__dirname}/public"
app.use express.static("#{__dirname}/public")
passport.use new TumblrStrategy
consumerKey: process.env.CONSUMER_KEY
consumerSecret: process.env.CONSUMER_SECRET
callbackURL: process.env.CALLBACK_URL
, (token, secret, profile, done)->
done null,
username: profile.username
token: token
secret: secret
passport.serializeUser (user, done)->
done null, user
passport.deserializeUser (user, done)->
done null, user
app.get '/', (req, res)-> res.render 'index'
app.get '/login', passport.authenticate 'tumblr'
app.get '/login/callback', passport.authenticate('tumblr', {failureRedirect: '/login'}), (req, res)->
res.cookie "username", req.user.username
res.cookie "token", req.user.token
res.redirect '/dashboard'
app.get '/dashboard', (req, res)-> res.render 'dashboard'
app.get '/api/dashboard', tumblr.dashboard
app.get '/api/tumblog', tumblr.tumblog
app.post '/api/post/:id/reblog', tumblr.reblog
app.listen process.env.PORT || 3000