Created
June 24, 2012 22:53
-
-
Save austinbv/2985366 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Module dependencies. | |
| */ | |
| var express = require('express'), | |
| routes = require('./routes'); | |
| var app = module.exports = express.createServer(); | |
| // Configuration | |
| app.configure(function(){ | |
| app.set('views', __dirname + '/views'); | |
| app.set('view engine', 'jade'); | |
| app.use(express.bodyParser()); | |
| app.use(express.methodOverride()); | |
| app.use(express.cookieParser()); | |
| app.use(express.session({ secret: 'your secret here' })); | |
| app.use(app.router); | |
| app.use(express['static'](__dirname + '/public')); | |
| }); | |
| app.configure('development', function(){ | |
| app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); | |
| }); | |
| app.configure('production', function(){ | |
| app.use(express.errorHandler()); | |
| }); | |
| // Routes | |
| console.log(routes); | |
| app.get('/calendar', routes.calendar); | |
| app.get('/', routes.index); | |
| app.listen(9999, function(){ | |
| console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > node app.js | |
| { index: [Function] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| https = require('https'); | |
| var buildUrl = function (date) { | |
| var today = new Date(date.getFullYear(), date.getMonth(), date.getDate()), | |
| tomorrow = new Date(today.getTime() + (1000 * 60 * 60 * 24)), | |
| baseUrl = '/calendar/v3/calendars', | |
| calendar = '#####@gmail.com', | |
| rest = 'events', | |
| queryString = { | |
| timeMax: tomorrow.toISOString(), | |
| timeMin: today.toISOString(), | |
| pp: 100, | |
| key: '###########################' | |
| }; | |
| return baseUrl + '/' + encodeURIComponent(calendar) + '/' + rest + '?' + $.param(queryString) + '&callback=?'; | |
| }; | |
| exports.calendar = function(req, res){ | |
| var calendar = ''; | |
| https.get({ | |
| host: 'www.googleapis.com', | |
| path: buildUrl(new Date) | |
| }, function(res) { | |
| res.on('data', function(chunk) { | |
| calendar += chunk; | |
| }); | |
| }); | |
| res.render(calendar); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exports.index = function(req, res){ | |
| res.render('index', { title: 'Express' }) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ○ > tree -L 2 -I- | |
| . | |
| ├── app.js | |
| ├── models | |
| │ └── event.js | |
| ├── node_modules | |
| │ ├── express | |
| │ ├── jade | |
| │ ├── mocha | |
| │ └── should | |
| ├── package.json | |
| ├── public | |
| │ ├── images | |
| │ ├── javascripts | |
| │ └── stylesheets | |
| ├── routes | |
| │ ├── calendar.js | |
| │ └── index.js | |
| ├── test | |
| └── views | |
| ├── index.jade | |
| └── layout.jade |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment