43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import fastify from 'fastify';
|
|
import jwt from '@fastify/jwt';
|
|
import dotenv from 'dotenv';
|
|
import { prismaPlugin } from './plugins/prisma';
|
|
import { authRoutes } from './routes/auth.routes';
|
|
import { roomRoutes } from './routes/rooms.routes';
|
|
import { batchRoutes } from './routes/batches.routes';
|
|
import { timeclockRoutes } from './routes/timeclock.routes';
|
|
|
|
dotenv.config();
|
|
|
|
const server = fastify({
|
|
logger: true
|
|
});
|
|
|
|
// Register Plugins
|
|
server.register(prismaPlugin);
|
|
server.register(jwt, {
|
|
secret: process.env.JWT_SECRET || 'supersecret'
|
|
});
|
|
|
|
// Register Routes
|
|
server.register(authRoutes, { prefix: '/api/auth' });
|
|
server.register(roomRoutes, { prefix: '/api/rooms' });
|
|
server.register(batchRoutes, { prefix: '/api/batches' });
|
|
server.register(timeclockRoutes, { prefix: '/api/timeclock' });
|
|
|
|
server.get('/healthz', async (request, reply) => {
|
|
return { status: 'ok', timestamp: new Date().toISOString() };
|
|
});
|
|
|
|
const start = async () => {
|
|
try {
|
|
const port = parseInt(process.env.PORT || '3000');
|
|
await server.listen({ port, host: '0.0.0.0' });
|
|
console.log(`Server listening on port ${port}`);
|
|
} catch (err) {
|
|
server.log.error(err);
|
|
process.exit(1);
|
|
}
|
|
};
|
|
|
|
start();
|