Fix API connectivity and import filament data from PDF

- Update all environment files to use new PostgreSQL API endpoint
- Fix CORS configuration in API server
- Import 35 filaments and 29 colors from PDF data
- Fix TypeScript type error in dashboard
- Add back emoji icons for dark mode toggle
- Remove debugging code and test buttons
- Clean up error handling
This commit is contained in:
DaX
2025-06-20 15:40:40 +02:00
parent 62a4891112
commit 82c476430f
13 changed files with 737 additions and 29 deletions

View File

@@ -19,10 +19,15 @@ app.use(cors({
origin: true, // Allow all origins in development
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization']
allowedHeaders: ['Content-Type', 'Authorization'],
exposedHeaders: ['Content-Length', 'Content-Type'],
maxAge: 86400
}));
app.use(express.json());
// Handle preflight requests
app.options('*', cors());
// Health check route
app.get('/', (req, res) => {
res.json({ status: 'ok', service: 'Filamenteka API' });
@@ -34,11 +39,14 @@ const authenticateToken = (req, res, next) => {
const token = authHeader && authHeader.split(' ')[1];
if (!token) {
return res.sendStatus(401);
return res.status(401).json({ error: 'Unauthorized' });
}
jwt.verify(token, process.env.JWT_SECRET || 'your-secret-key', (err, user) => {
if (err) return res.sendStatus(403);
if (err) {
console.error('JWT verification error:', err);
return res.status(403).json({ error: 'Invalid token' });
}
req.user = user;
next();
});
@@ -111,8 +119,9 @@ app.delete('/api/colors/:id', authenticateToken, async (req, res) => {
}
});
// Filaments endpoints
// Filaments endpoints (PUBLIC - no auth required)
app.get('/api/filaments', async (req, res) => {
console.log('Filaments request headers:', req.headers);
try {
const result = await pool.query('SELECT * FROM filaments ORDER BY created_at DESC');
res.json(result.rows);