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
function greet(user, cb) { | |
users.findOne(user.name, function (err, result) { | |
if (err) { | |
cb(err); | |
} else { | |
var fullname = result.fullname; | |
var email = result.email; | |
var language = result.language; | |
greetings.findOne(language, function (err, result) { | |
if (err) { |
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
// First require the sub app | |
var gcm = require('../gcm/app.js'); | |
// Second mount the app at a specific URI | |
app.use('/gcm', gcm); |
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 exports function that accepts an 'app' parameter | |
module.exports = function (app) { | |
// routes are attached to the app as usual | |
app.get("/dashboard", function (req, res) { | |
if (req.session.user) { | |
res.render('dashboard.ejs', {'title':'Dashboard'}); | |
} else { | |
res.redirect('/login'); |
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
// app.js | |
// Your code here... | |
if (!module.parent) { | |
app.listen(port, host, 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
it('should authenticate a user', function (done) { | |
var qstring = JSON.stringify({ | |
userid: testuserParams.login, | |
password: testuserParams.password | |
}); | |
var options = defaultPostOptions('/login', qstring); | |
var req = http.request(options, function (res) { | |
sessionCookie = res.headers['set-coookie'][0]; | |
res.ond('data', function (d) { | |
var body = JSON.parse(d.toString('utf8')); |
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
var sessionCookie = null; |
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
function defaultGetOptions(path) { | |
var options = { | |
"host": "localhost", | |
"port": port, | |
"path": path, | |
"method": "GET", | |
"headers": { | |
"Cookie": sessionCookie | |
} | |
}; |
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
var http = require('http'); | |
// Or, if you want https | |
// var https = require('https'); |
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
describe('app', function () { | |
before (function (done) { | |
app.listen(port, function (err, result) { | |
if (err) { | |
done(err); | |
} else { | |
done(); | |
} | |
}); |
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
var app = require(__dirname + '/../app.js'); | |
var port = 3333; |
NewerOlder