Initial commit: redefined-designs storefront
This commit is contained in:
Executable
+59
@@ -0,0 +1,59 @@
|
||||
import express from 'express';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import path from 'path';
|
||||
import { pool } from './db';
|
||||
import itemsRouter from './routes/items';
|
||||
import { router as paypalRouter, webhookRouter as paypalWebhookRouter } from './routes/paypal';
|
||||
import adminRouter from './routes/admin';
|
||||
import adminCustomersRouter from './routes/adminCustomers';
|
||||
import demoRouter from './routes/demo';
|
||||
import customersRouter from './routes/customers';
|
||||
import publicRouter from './routes/public';
|
||||
import { attachCustomer } from './middleware/customerAuth';
|
||||
|
||||
const app = express();
|
||||
app.set('trust proxy', 1);
|
||||
|
||||
app.use('/webhooks/paypal', express.json(), paypalWebhookRouter);
|
||||
app.use(express.json());
|
||||
app.use(cookieParser());
|
||||
app.use(attachCustomer);
|
||||
app.use('/uploads', express.static('/app/uploads'));
|
||||
|
||||
app.get('/api/config', (_req, res) => {
|
||||
const clientId = process.env.PAYPAL_CLIENT_ID;
|
||||
const isPlaceholder = !clientId || clientId.length < 10 || clientId === 'REPLACE_WITH_PAYPAL_CLIENT_ID';
|
||||
res.json({
|
||||
paypalClientId: isPlaceholder ? null : clientId,
|
||||
demoMode: process.env.DEMO_MODE !== 'false',
|
||||
currency: process.env.SITE_CURRENCY || 'USD'
|
||||
});
|
||||
});
|
||||
|
||||
app.use('/api/items', itemsRouter);
|
||||
app.use('/api/checkout/paypal', paypalRouter);
|
||||
app.use('/api/checkout/demo', demoRouter);
|
||||
app.use('/api/admin/customers', adminCustomersRouter);
|
||||
app.use('/api/admin', adminRouter);
|
||||
app.use('/api/customers', customersRouter);
|
||||
app.use('/', publicRouter);
|
||||
|
||||
const staticDir = path.join(__dirname, '..', 'public');
|
||||
app.use(express.static(staticDir));
|
||||
app.get('*', (_req, res) => {
|
||||
res.sendFile(path.join(staticDir, 'index.html'));
|
||||
});
|
||||
|
||||
setInterval(async () => {
|
||||
try {
|
||||
await pool.query(
|
||||
`UPDATE items SET status = 'available', reserved_until = NULL, paypal_order_id = NULL
|
||||
WHERE status = 'reserved' AND reserved_until < now()`
|
||||
);
|
||||
} catch (err) {
|
||||
console.error('reservation sweep failed:', (err as Error).message);
|
||||
}
|
||||
}, 60 * 1000);
|
||||
|
||||
const PORT = parseInt(process.env.PORT || '3000', 10);
|
||||
app.listen(PORT, () => console.log(`redefined-designs listening on ${PORT}`));
|
||||
Reference in New Issue
Block a user