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
…#434)

* 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.

* expose port

---------

Co-authored-by: Jason Young <jason_y54@protonmail.com>
  • Loading branch information
EandrewJones and Jyyjy authored Apr 30, 2024
1 parent 01295de commit 04cfcb1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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/

EXPOSE 8000

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 04cfcb1

Please sign in to comment.