Created
February 12, 2015 19:11
-
-
Save FrankGrimm/c08f55f5a6338898f6cf 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
var express = require('express'); | |
var nodemailer = require('./src/nodemailer'); // note that i changed the path to fit my setup | |
var router = express.Router(); | |
router.get('/', renderJobsPage); | |
router.post('/', sendResume); | |
function renderJobsPage (req, res, next) { | |
res.send('<html><head></head><body><form action="/" method="post"><input type="email" name="email" id="email" /></form></body></html>'); | |
next(); | |
} | |
function sendResume(req, res, next) { | |
console.log('got POST request - body? ' + (req.body && req.body.email ? 'yes' : 'no')); | |
if (req.body && req.body.email) { | |
nodemailer(req, res, next); | |
} else { | |
renderJobsPage(req, res, next); | |
} | |
} | |
module.exports = router; |
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
// src/nodemailer.js | |
module.exports = function(req, res, next) { | |
console.log(require('util').inspect(req.body)); | |
res.send(require('util').inspect(req.body)); | |
next(); | |
}; |
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
// very crude, just for inspiration ;) | |
var express = require('express'); | |
var app = express(); | |
var bodyParser = require('body-parser') | |
// parse application/x-www-form-urlencoded | |
app.use(bodyParser.urlencoded({ extended: false })) | |
// parse application/json | |
app.use(bodyParser.json()) | |
app.use('/', require('./jobs.js')); | |
app.listen(6000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment