diff --git a/samples/nodejs-file-upload/Dockerfile b/samples/nodejs-file-upload/Dockerfile new file mode 100644 index 00000000..a8a535f8 --- /dev/null +++ b/samples/nodejs-file-upload/Dockerfile @@ -0,0 +1,27 @@ +# Use an official Node runtime based on slim as a parent image +FROM node:20-slim + +# Set the working directory to /app +WORKDIR /app + +# Install curl and any other dependencies +RUN apt-get update \ + \ + && apt-get install -y --no-install-recommends \ + curl \ + && rm -rf /var/lib/apt/lists/* + +# Copy package.json and package-lock.json into the container at /app +COPY package*.json ./ + +# Install any needed packages specified in package.json +RUN npm install + +# Copy the current directory contents into the container +COPY . . + +# Make port 3000 available to the world outside this container +EXPOSE 3000 + +# Run the app when the container launches +ENTRYPOINT [ "node", "main.js" ] diff --git a/samples/nodejs-file-upload/compose.yaml b/samples/nodejs-file-upload/compose.yaml new file mode 100644 index 00000000..96cd1ed1 --- /dev/null +++ b/samples/nodejs-file-upload/compose.yaml @@ -0,0 +1,12 @@ +services: + service1: + restart: always + build: + context: . + dockerfile: Dockerfile + ports: + - mode: ingress + target: 3000 + published: 3000 + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:3000/"] \ No newline at end of file diff --git a/samples/nodejs-file-upload/main.js b/samples/nodejs-file-upload/main.js new file mode 100644 index 00000000..d1663346 --- /dev/null +++ b/samples/nodejs-file-upload/main.js @@ -0,0 +1,39 @@ +const express = require('express'); +const multer = require('multer'); +const fs = require('fs'); +const path = require('path'); + +const app = express(); +const upload = multer({ dest: 'uploads/' }); + +app.use(express.static('uploads')); + +app.get('/', (req, res) => { + fs.readdir('uploads', (err, files) => { + if (err) { + return res.status(500).send('Unable to scan files!'); + } + let fileList = files.map(file => `