back-end ustreamer, GPS, timelapse, and photo-refresh site working

This commit is contained in:
2025-07-27 15:10:11 -07:00
parent 7496df0174
commit b740ba9991
22 changed files with 443 additions and 99 deletions

View File

@ -0,0 +1,23 @@
# Use an official Node runtime as a parent image
FROM node:14
# Create and change to the app directory
WORKDIR /usr/src/app
# Copy package.json and package-lock.json
COPY package*.json ./
# Install any needed packages specified in package.json
RUN npm install
# Bundle app source inside Docker container
COPY . .
# Make port 3000 available to the world outside this container
EXPOSE 3000
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["node", "server.js"]

View File

@ -0,0 +1,12 @@
{
"name": "docker_web_app",
"version": "1.0.0",
"description": "A simple Docker Web app",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.17.1"
}
}

View File

@ -0,0 +1,39 @@
const express = require('express');
const fs = require('fs');
const path = require('path');
const app = express();
const port = 3000;
app.use(express.static('public')); // Serve static files from the 'public' directory
// Endpoint to get the most recent image
app.get('/most-recent-image', (req, res) => {
const imagesDirectory = path.join(__dirname, 'images');
fs.readdir(imagesDirectory, (err, files) => {
if (err) {
return res.status(500).send('Unable to scan directory');
}
let mostRecentImage = null;
let maxDate = Date.now();
files.forEach(file => {
const filePath = path.join(imagesDirectory, file);
const stats = fs.statSync(filePath);
if (stats.isFile() && /\.(jpg|jpeg|png|gif)$/i.test(file)) {
const currentDate = new Date(stats.mtime).getTime();
if (currentDate < maxDate) {
mostRecentImage = file;
maxDate = currentDate;
}
}
});
if (mostRecentImage) {
res.json({ imagePath: `/images/${mostRecentImage}` });
} else {
res.status(404).send('No images found');
}
});
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});