Skapar en container med dockerfil och allt
This commit is contained in:
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
npm-debug.log
|
||||
20
Dockerfile
Normal file
20
Dockerfile
Normal file
@@ -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"]
|
||||
18
docker-compose.yml
Normal file
18
docker-compose.yml
Normal file
@@ -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"
|
||||
|
||||
12
server.js
12
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.');
|
||||
|
||||
Reference in New Issue
Block a user