From 28415ab8502f688aa0069350538cad038805e3bd Mon Sep 17 00:00:00 2001 From: Evan Jones Date: Thu, 25 Apr 2024 20:56:10 -0400 Subject: [PATCH] feat(Dockerfile) adds docker file to containerized the example server 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. --- Dockerfile | 11 +++++++++++ example/server.js | 5 +++++ 2 files changed, 16 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..a31ccf2b --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/example/server.js b/example/server.js index 0f983c77..94accdb1 100644 --- a/example/server.js +++ b/example/server.js @@ -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';