Skip to content

Commit

Permalink
feat(Dockerfile) adds docker file to containerized the example server
Browse files Browse the repository at this point in the history
Dockerizes the example server js for easier portability.
Fixes a bug in server.js so that empty logs are no longer
written out to the active JSON file buffer.
  • Loading branch information
EandrewJones committed Apr 29, 2024
1 parent 01295de commit 28415ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ARG BUILDPLATFORM=${BUILDPLATFORM:-amd64}
FROM --platform=${BUILDPLATFORM} node:18-bullseye-slim AS flagon-node

WORKDIR /app
RUN --mount=type=bind,target=./package.json,src=./package.json \
--mount=type=bind,target=./package-lock.json,src=./package-lock.json \
npm ci
COPY ./src src/
COPY ./example example/

CMD ["node", "example/server.js"]
5 changes: 5 additions & 0 deletions example/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ app.get('/', function (req, res) {

app.post('/', function (req, res) {
const body = typeof req.body === "string" ? JSON.parse(req.body) : req.body

const isEmptyArray = (Array.isArray(body) && body.length === 0);
const isEmptyObject = (typeof body === 'object' && body !== null && Object.keys(body).length === 0);
if (isEmptyArray || isEmptyObject) return

console.log(body)

let delimiter = ',\n\t';
Expand Down

0 comments on commit 28415ab

Please sign in to comment.