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
| .then(() => { | |
| if (newJobs.length) { | |
| var nexmo = new Nexmo({ | |
| apiKey: NEXMO_API_KEY, | |
| apiSecret: NEXMO_API_SECRET | |
| }); | |
| nexmo.message.sendSms('Donkey Jobs Finder', MY_PHONE_NUMBER, 'Hello, we found a new donkey job!'); | |
| } | |
| callback(null, { jobs: newJobs }); | |
| }) |
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 formatJobs (list) { | |
| return list.reduce((acc, job) => { | |
| return `${acc}${job.job} in ${job.location} closing on ${moment(job.closing).format('LL')}\n\n`; | |
| }, 'We found:\n\n'); | |
| } | |
| module.exports = { | |
| extractListingsFromHTML, | |
| formatJobs | |
| }; |
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
| const app = express(); | |
| const PORT = 3000; | |
| app.listen(PORT, (err) => { | |
| if (err) console.log(err); | |
| else console.log(`App listening on port ${PORT}`) | |
| }); |
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
| const http = require('http'); | |
| function hexpress () { | |
| const nodeServer = http.createServer((req, res) => { | |
| // respond? | |
| }); | |
| const app = { | |
| listen: (...args) => { | |
| nodeServer.listen(...args); | |
| return nodeServer; |
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
| const http = require('http'); | |
| const url = require('url'); | |
| function Hexpress () { | |
| } | |
| Hexpress.prototype.listen = function (...args) { | |
| const nodeServer = http.createServer((req, res) => { | |
| const {pathname} = url.parse(req.url); |
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 addResMethods(res) { | |
| res.status = function (code) { | |
| this.statusCode = code; | |
| return this; | |
| }; | |
| res.sendStatus = function (code) { | |
| this.statusCode = code; | |
| this.write(getAppropriateTextResponse(code)); | |
| this.end(); |
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
| Hexpress.prototype.listen = function (...args) { | |
| const nodeServer = http.createServer((req, res) => { | |
| res = addResMethods(res); | |
| // now we have more methods to use! | |
| res.status(200).send('Can I tempt you with a half price cauldron?'); | |
| }); | |
| nodeServer.listen(...args); | |
| return nodeServer; |
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
| const app = express(); | |
| app.get('/api', (req, res) => res.send('All good')); | |
| app.get('/api/hexes', (req, res) => res.send('So many hexes...')); | |
| app.get('/api/hexes/words', (req, res) => res.send('List of words for hexes')); | |
| app.delete('/api/hexes/:id', (req, res) => res.send(`Hex Number ${req.params.id} successfully deleted`)); |
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 Hexpress () { | |
| this.routeMappings = {}; | |
| }; | |
| Hexpress.prototype.get = function (route, handler) { | |
| this.routeMappings[`GET ${route}`] = handler; | |
| }; | |
| // Usage: |
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
| Hexpress.prototype.listen = function (...args) { | |
| const nodeServer = http.createServer(function (req, res) { | |
| res = addResMethods(res); | |
| // What handler should I choose from our object? | |
| const reqKey = `${req.method} ${req.url}`; | |
| if (this.routeMappings[reqKey]) return this.routeMappings[reqKey](req, res); | |
| else defaultResponse(req, res) | |