forked from frosas/google-plus-user-feed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
53 lines (44 loc) · 1.5 KB
/
app.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
52
53
require('sugar')
var googlePlus = require('./lib/google-plus'),
express = require('express'),
errors = require('./lib/errors')
var app = express.createServer()
app.configure(function() {
app.use(express.static(__dirname + '/public'))
app.set('views', __dirname + '/views')
app.set('view engine', 'ejs')
app.set('view options', {layout: false})
})
app.get('/', function(request, response) {
response.render('home')
})
app.get('/:id', function(request, response, next) {
var userId = request.params.id
if (! /^[0-9]+$/.test(userId)) return next()
var plus = new googlePlus.GooglePlus(process.env.GOOGLE_API_KEY)
plus.userPosts(userId, function(error, posts) {
if (error) return next(error)
response.contentType('text/xml')
response.render('feed', {
profileUrl: 'https://plus.google.com/' + userId,
posts: posts,
})
})
})
app.get('/feed.xsl', function(request, response) {
response.render('feed-xsl')
})
app.get('/*', function(request, response, next) {
next(new errors.NotFoundError)
})
app.error(function(error, request, response, next) {
response.header('Content-Type', 'text/plain')
if (error instanceof errors.UserError) {
var code = error instanceof errors.NotFoundError ? 404 : 400
response.send(error.message, code)
} else {
console.error(error.message)
response.send(error.publicMessage || "Internal Error", 500)
}
})
app.listen(process.env.PORT || 8080)