46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import express from 'express';
|
|
import cors from 'cors';
|
|
import { join, dirname } from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import { existsSync } from 'fs';
|
|
import itemsRouter from './routes/items.js';
|
|
import uploadsRouter, { createFileUploadRouter, createFileDeleteRouter } from './routes/uploads.js';
|
|
import statsRouter from './routes/stats.js';
|
|
import suggestionsRouter from './routes/suggestions.js';
|
|
import locationsRouter from './routes/locations.js';
|
|
import categoriesRouter from './routes/categories.js';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3001;
|
|
|
|
app.use(cors());
|
|
app.use(express.json());
|
|
|
|
// API routes
|
|
app.get('/api/health', (_req, res) => {
|
|
res.json({ status: 'ok' });
|
|
});
|
|
|
|
app.use('/api/items', itemsRouter);
|
|
app.use('/api/items', createFileUploadRouter());
|
|
app.use('/api/files', createFileDeleteRouter());
|
|
app.use('/api/uploads', uploadsRouter);
|
|
app.use('/api/stats', statsRouter);
|
|
app.use('/api/suggestions', suggestionsRouter);
|
|
app.use('/api/locations', locationsRouter);
|
|
app.use('/api/categories', categoriesRouter);
|
|
|
|
// Serve static client in production
|
|
const clientDist = join(__dirname, '..', '..', 'client', 'dist');
|
|
if (existsSync(clientDist)) {
|
|
app.use(express.static(clientDist));
|
|
app.get('/{*path}', (_req, res) => {
|
|
res.sendFile(join(clientDist, 'index.html'));
|
|
});
|
|
}
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`Server running on http://localhost:${PORT}`);
|
|
});
|