diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5171c54 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +npm-debug.log \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..57ec642 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Use the official Node.js image as the base image +FROM node:14 + +# Set the working directory +WORKDIR /usr/src/app + +# Copy package.json and package-lock.json +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Copy the rest of the application code +COPY . . + +# Expose the port the app runs on +EXPOSE 3044 + +# Command to run the application +CMD ["node", "server.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c5b4e74 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +version: '3.8' + +services: + org-todo-pwa: + image: org-todo-pwa + build: . + ports: + - "3044:3044" + volumes: + - /srv/swarm/org-todo-pwa/data:/data + deploy: + labels: + - "traefik.enable=true" + - "traefik.http.routers.plan.tls=true" + - "traefik.http.routers.plan.tls.certresolver=myhttpchallenge" + - "traefik.http.routers.plan.rule=Host(`todo. casablanca.wahlberg.se`)" + - "traefik.http.routers.plan.entrypoints=websecure" + \ No newline at end of file diff --git a/server.js b/server.js index 5483cca..f9331bd 100644 --- a/server.js +++ b/server.js @@ -9,6 +9,12 @@ const port = 3044; app.use(bodyParser.json()); app.use(express.static('public')); +// Ensure the /data directory exists +const dataDir = path.join('/data'); +if (!fs.existsSync(dataDir)) { + fs.mkdirSync(dataDir, { recursive: true }); +} + // Endpoint to receive task data and append to file app.post('/add-task', (req, res) => { const { subject, description, scheduled } = req.body; @@ -18,7 +24,7 @@ app.post('/add-task', (req, res) => { * TODO ${subject} SCHEDULED: <${scheduled}> :LOGBOOK: - - State "TODO" from [${currentDateTime}] + - State "TODO" from "TODO" [${currentDateTime}] :END: `; @@ -28,12 +34,12 @@ app.post('/add-task', (req, res) => { ${description} SCHEDULED: <${scheduled}> :LOGBOOK: - - State "TODO" from [${currentDateTime}] + - State "TODO" from "TODO" [${currentDateTime}] :END: `; } - const filePath = path.join(__dirname, 'tasks.org'); + const filePath = path.join(dataDir, 'tasks.org'); fs.appendFile(filePath, orgFormattedData, (err) => { if (err) { return res.status(500).send('Error writing to file.');