forked from tlhunter/distributed-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4cb4ccb
Showing
104 changed files
with
8,033 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# npm packages | ||
node_modules | ||
|
||
# Temp file | ||
/index.html | ||
|
||
# NYC Code Coverage | ||
coverage/ | ||
|
||
# Sample binary files | ||
*.bin | ||
|
||
# TLS Files | ||
*.key | ||
*.cert | ||
*.pem | ||
*.csr | ||
*.srl |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Distributed Systems with Node.js: Companion Files | ||
|
||
These are the companion files for Distributed Systems with Node.js, O'Reilly 2020. These files aren't required to follow along with the book; the book contains everything you need to recreate them. However, they're provided here as a convenience. | ||
|
||
If you can't get a program to run you may find that by looking at these files you've made a typo. Or, you may find that one day an npm package update causes an incompatibility in your program, at which point a _package-lock.json_ file in here may help you out. | ||
|
||
- [Distributed Systems with Node.js on O'Reilly](https://learning.oreilly.com/library/view/distributed-systems-with/9781492077282/) | ||
- [Distributed Systems with Node.js on Amazon](https://www.amazon.com/Distributed-Systems-Node-js-Building-Enterprise-Ready/dp/1492077291) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "audit", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"hoek": "^4.2.0", | ||
"js-yaml": "^3.9.1" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env node | ||
|
||
// npm install fastify@3.2 ioredis@4.17 pg@8.3 | ||
const server = require('fastify')(); | ||
const HOST = '0.0.0.0'; | ||
const PORT = 3300; | ||
const redis = new (require("ioredis"))({enableOfflineQueue: false}); | ||
const pg = new (require('pg').Client)(); | ||
pg.connect(); // Note: Postgres will not reconnect on failure | ||
|
||
server.get('/health', async (req, reply) => { | ||
try { | ||
const res = await pg.query('SELECT $1::text as status', ['ACK']); | ||
if (res.rows[0].status !== 'ACK') reply.code(500).send('DOWN'); | ||
} catch(e) { | ||
reply.code(500).send('DOWN'); | ||
} | ||
// ... other down checks ... | ||
let status = 'OK'; | ||
try { | ||
if (await redis.ping() !== 'PONG') status = 'DEGRADED'; | ||
} catch(e) { | ||
status = 'DEGRADED'; | ||
} | ||
// ... other degraded checks ... | ||
reply.code(200).send(status); | ||
}); | ||
|
||
server.listen(PORT, HOST, () => console.log(`http://${HOST}:${PORT}/`)); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env node | ||
|
||
const HOST = process.env.HOST || '127.0.0.1'; | ||
const PORT = process.env.PORT || 4000; | ||
|
||
require("http").createServer((req, res) => { | ||
res.end('ok'); | ||
}).listen(PORT, () => { | ||
console.log(`Producer running at http://${HOST}:${PORT}`); | ||
}); |
Oops, something went wrong.