Use API
This commit is contained in:
parent
30825d4ee1
commit
567ffea181
7 changed files with 157 additions and 86 deletions
|
|
@ -3,4 +3,8 @@ PORT=3001
|
|||
NODE_ENV=development
|
||||
|
||||
# CORS Configuration
|
||||
FRONTEND_URL=*
|
||||
FRONTEND_URL=*
|
||||
|
||||
# File Paths
|
||||
DATA_PATH=../fizika.json
|
||||
PICS_PATH=../pics
|
||||
|
|
@ -56,8 +56,8 @@ A secure Node.js/Express backend for managing physics quiz questions and images
|
|||
```
|
||||
|
||||
4. **Access the admin interface:**
|
||||
- Open http://localhost:3001/admin.html
|
||||
- Default password: `admin123` (change this!)
|
||||
- Open http://localhost:3001/
|
||||
- No authentication required
|
||||
|
||||
### Local Development
|
||||
|
||||
|
|
@ -169,7 +169,7 @@ The project includes a GitHub Actions workflow that:
|
|||
|
||||
## Admin Interface
|
||||
|
||||
Access the admin interface at `/admin.html`:
|
||||
Access the admin interface at `/`:
|
||||
- **Questions Tab**: Add, edit, delete quiz questions
|
||||
- **Images Tab**: Upload and manage image files
|
||||
- **Responsive Design**: Works on desktop and mobile
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ services:
|
|||
- NODE_ENV=production
|
||||
- PORT=3001
|
||||
- FRONTEND_URL=${FRONTEND_URL:-*}
|
||||
- DATA_PATH=${DATA_PATH:-/usr/src/app/fizika.json}
|
||||
- PICS_PATH=${PICS_PATH:-/usr/src/app/pics}
|
||||
volumes:
|
||||
# Mount data files
|
||||
- ./fizika.json:/usr/src/app/fizika.json:ro
|
||||
|
|
@ -37,6 +39,8 @@ services:
|
|||
- NODE_ENV=development
|
||||
- PORT=3001
|
||||
- FRONTEND_URL=*
|
||||
- DATA_PATH=/usr/src/app/fizika.json
|
||||
- PICS_PATH=/usr/src/app/pics
|
||||
volumes:
|
||||
- ./backend:/usr/src/app
|
||||
- ./fizika.json:/usr/src/app/fizika.json
|
||||
|
|
|
|||
|
|
@ -15,16 +15,25 @@ app.use(cors({
|
|||
credentials: true
|
||||
}));
|
||||
|
||||
app.use(express.json({ limit: '10mb' }));
|
||||
app.use(express.json({ limit: '100mb' }));
|
||||
app.use(express.static('public'));
|
||||
|
||||
// File paths
|
||||
const DATA_PATH = path.join(__dirname, '../frontend/fizika.json');
|
||||
const PICS_PATH = path.join(__dirname, '../frontend/pics');
|
||||
const DATA_PATH = process.env.DATA_PATH || path.join(__dirname, '../fizika.json');
|
||||
const PICS_PATH = process.env.PICS_PATH || path.join(__dirname, '../pics');
|
||||
|
||||
// Multer configuration for image uploads
|
||||
const storage = multer.diskStorage({
|
||||
destination: (req, file, cb) => {
|
||||
cb(null, PICS_PATH);
|
||||
},
|
||||
filename: (req, file, cb) => {
|
||||
cb(null, file.originalname);
|
||||
}
|
||||
});
|
||||
|
||||
const upload = multer({
|
||||
dest: PICS_PATH,
|
||||
storage: storage,
|
||||
limits: { fileSize: 5 * 1024 * 1024 }, // 5MB
|
||||
fileFilter: (req, file, cb) => {
|
||||
if (file.mimetype.startsWith('image/')) {
|
||||
|
|
@ -32,9 +41,6 @@ const upload = multer({
|
|||
} else {
|
||||
cb(new Error('Only images allowed'));
|
||||
}
|
||||
},
|
||||
filename: (req, file, cb) => {
|
||||
cb(null, file.originalname);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue