Skip to content

Commit 564d992

Browse files
committed
web example added
1 parent 48d3fdd commit 564d992

20 files changed

Lines changed: 965 additions & 1 deletion

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
Dockerfile
3+
*.md
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM node:16-alpine
2+
3+
WORKDIR /opt/app
4+
5+
COPY . .
6+
7+
RUN npm ci
8+
9+
CMD ["npm", "start"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = ({
2+
port: +process.env.PORT || 3000,
3+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const Chance = require('chance');
2+
3+
const chance = new Chance();
4+
5+
module.exports.getRandom = (start, end) => Math.floor((Math.random() * end) + start);
6+
7+
module.exports.delay = (delaySeconds) => new Promise((resolve) => {
8+
setTimeout(() => {
9+
resolve();
10+
}, delaySeconds * 1_000);
11+
});
12+
13+
14+
module.exports.getQuote = () => chance.sentence();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const express = require('express');
2+
const { port } = require('./config');
3+
const { getQuote } = require('./helpers');
4+
5+
const app = express();
6+
7+
// curl -X GET "http://localhost:3000/quote"
8+
app.get('/quote', async (_, res) => {
9+
try {
10+
const quote = getQuote();
11+
res.send(quote);
12+
} catch (ex) {
13+
res.status(500).end(ex);
14+
}
15+
});
16+
17+
app.listen(port, () => {
18+
console.log(`Listenning at ${port}`);
19+
});

0 commit comments

Comments
 (0)