Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
tlhunter committed Oct 28, 2020
0 parents commit 4cb4ccb
Show file tree
Hide file tree
Showing 104 changed files with 8,033 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .gitignore
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
8 changes: 8 additions & 0 deletions README.md
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)
40 changes: 40 additions & 0 deletions audit/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions audit/package.json
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"
}
}
29 changes: 29 additions & 0 deletions basic-http-healthcheck.js
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}/`));
10 changes: 10 additions & 0 deletions benchmark/native-http.js
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}`);
});
Loading

0 comments on commit 4cb4ccb

Please sign in to comment.