diff --git a/node_api/Dockerfile b/node_api/Dockerfile new file mode 100644 index 0000000..21cd634 --- /dev/null +++ b/node_api/Dockerfile @@ -0,0 +1,20 @@ +FROM node:16-bullseye-slim + +RUN apt update +RUN apt install build-essential -y +RUN apt install python3 -y +RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app + +WORKDIR /home/node/app +USER node + +EXPOSE 3000 + +COPY --chown=node:node . . + +RUN chmod -R 777 /home/node/app +RUN npm install -D --force + +RUN npm run build + +CMD ["node", "/home/node/app/api/index.js"] \ No newline at end of file diff --git a/node_api/api/index.js b/node_api/api/index.js index f5618a1..479637d 100644 --- a/node_api/api/index.js +++ b/node_api/api/index.js @@ -1,6 +1,7 @@ require('dotenv').config() const express = require("express") +const path = require("path") const cors = require("cors") const mlib = require("../../node_lib") @@ -32,6 +33,13 @@ async function main() { res.json(phrases) }) + app.use(express.static(path.join(__dirname, "..", "web", "dist",))) + + // serve static react build + app.get("*", (req, res) => { + res.sendFile(path.join(__dirname, "..", "web", "dist", "index.html")) + }) + app.listen(PORT) console.log(`Listening on port ${PORT}`) diff --git a/node_api/docker-compose.yml b/node_api/docker-compose.yml new file mode 100644 index 0000000..fba3f55 --- /dev/null +++ b/node_api/docker-compose.yml @@ -0,0 +1,9 @@ +version: "3" + +services: + web: + container_name: monstercanker-service + build: . + restart: unless-stopped + ports: + - "3000:3000" \ No newline at end of file