Initial commit: simple file server
Add a new simple-file-server project. Includes Express server, auth and file routes, static client assets (public), and a db/connection module that uses MariaDB to log file actions and initialize a users table. Add Dockerfile and docker-compose.yml (exposes 3000 → 8080 and mounts ./uploads), .env.example, .gitignore, package.json and package-lock.json, and an uploads scaffold. This provides a ready-to-run app with container support and basic DB integration.
This commit is contained in:
16
uploads/Think/Dockerfile
Normal file
16
uploads/Think/Dockerfile
Normal file
@@ -0,0 +1,16 @@
|
||||
FROM node:18-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
|
||||
COPY . .
|
||||
|
||||
# Expose port 3000
|
||||
EXPOSE 3000
|
||||
|
||||
# Create uploads directory
|
||||
RUN mkdir -p uploads
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
2165
uploads/Think/all/package-lock.json
generated
Normal file
2165
uploads/Think/all/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
24
uploads/Think/all/package.json
Normal file
24
uploads/Think/all/package.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "simple-file-server",
|
||||
"version": "1.0.0",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node server.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"adm-zip": "^0.5.16",
|
||||
"archiver": "^7.0.1",
|
||||
"bcryptjs": "^3.0.3",
|
||||
"cors": "^2.8.6",
|
||||
"dotenv": "^17.2.4",
|
||||
"express": "^5.2.1",
|
||||
"express-session": "^1.19.0",
|
||||
"mariadb": "^3.4.5",
|
||||
"multer": "^2.0.2"
|
||||
}
|
||||
}
|
||||
51
uploads/Think/all/server.js
Normal file
51
uploads/Think/all/server.js
Normal file
@@ -0,0 +1,51 @@
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const path = require('path');
|
||||
const session = require('express-session');
|
||||
require('dotenv').config();
|
||||
|
||||
const { initUserTable } = require('./db/connection');
|
||||
const authRoutes = require('./routes/auth');
|
||||
const fileRoutes = require('./routes/files');
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
// Initialize DB
|
||||
initUserTable();
|
||||
|
||||
// Middleware
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
// Session
|
||||
app.use(session({
|
||||
secret: process.env.SESSION_SECRET || 'supersecretkey',
|
||||
resave: false,
|
||||
saveUninitialized: false,
|
||||
cookie: { secure: false } // Set to true if using HTTPS
|
||||
}));
|
||||
|
||||
// Auth Middleware
|
||||
const requireAuth = (req, res, next) => {
|
||||
if (req.session.user) {
|
||||
next();
|
||||
} else {
|
||||
res.status(401).json({ error: 'Unauthorized' });
|
||||
}
|
||||
};
|
||||
|
||||
// Routes
|
||||
app.use('/api/auth', authRoutes);
|
||||
app.use('/api', requireAuth, fileRoutes);
|
||||
|
||||
// Static files (public) - protect if needed, but for now let's allow loading the app
|
||||
// We can protect specific assets if we want, but the API is protected.
|
||||
// Actually, if we want to force login, we can serve a login page or handle it in specific separate file.
|
||||
// The main `index.html` handles the login UI, so it should be public.
|
||||
app.use(express.static('public'));
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server running on port ${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user