67 lines
1.9 KiB
JavaScript
67 lines
1.9 KiB
JavaScript
import express from 'express';
|
|
import cors from 'cors';
|
|
import dotenv from 'dotenv';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import { dirname } from 'path';
|
|
|
|
// Import routes
|
|
import authRoutes from './routes/auth.js';
|
|
import modelsRoutes from './routes/models.js';
|
|
import collectionsRoutes from './routes/collections.js';
|
|
import tagsRoutes from './routes/tags.js';
|
|
import bulkRoutes from './routes/bulk.js';
|
|
import printQueueRoutes from './routes/printQueue.js';
|
|
import exportRoutes from './routes/export.js';
|
|
import importRoutes from './routes/import.js';
|
|
import printersRoutes from './routes/printers.js';
|
|
|
|
// Import database to initialize
|
|
import './database.js';
|
|
|
|
dotenv.config();
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
// Middleware
|
|
app.use(cors());
|
|
app.use(express.json());
|
|
app.use(express.urlencoded({ extended: true }));
|
|
|
|
// Serve static files (uploaded models)
|
|
app.use('/uploads', express.static(path.join(__dirname, '..', 'uploads')));
|
|
|
|
// Serve frontend static files
|
|
app.use(express.static(path.join(__dirname, '..', 'client')));
|
|
|
|
// API Routes
|
|
app.use('/api/auth', authRoutes);
|
|
app.use('/api/models', modelsRoutes);
|
|
app.use('/api/collections', collectionsRoutes);
|
|
app.use('/api/tags', tagsRoutes);
|
|
app.use('/api/bulk', bulkRoutes);
|
|
app.use('/api/print-queue', printQueueRoutes);
|
|
app.use('/api/export', exportRoutes);
|
|
app.use('/api/import', importRoutes);
|
|
app.use('/api/printers', printersRoutes);
|
|
|
|
// Health check
|
|
app.get('/api/health', (req, res) => {
|
|
res.json({ status: 'ok', message: 'MakerStash is running' });
|
|
});
|
|
|
|
// Serve frontend for all other routes
|
|
app.get('*', (req, res) => {
|
|
res.sendFile(path.join(__dirname, '..', 'client', 'index.html'));
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`Server is running on http://localhost:${PORT}`);
|
|
console.log(`API available at http://localhost:${PORT}/api`);
|
|
});
|
|
|
|
export default app;
|