From 28415ab8502f688aa0069350538cad038805e3bd Mon Sep 17 00:00:00 2001 From: Evan Jones Date: Thu, 25 Apr 2024 20:56:10 -0400 Subject: [PATCH 1/2] 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'; From a8a0119cd09b47cf3c0dcda3f15e174326e1524f Mon Sep 17 00:00:00 2001 From: Jason Young Date: Tue, 30 Apr 2024 13:01:27 -0400 Subject: [PATCH 2/2] expose port --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index a31ccf2b..14e01a7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,6 @@ RUN --mount=type=bind,target=./package.json,src=./package.json \ COPY ./src src/ COPY ./example example/ +EXPOSE 8000 + CMD ["node", "example/server.js"]