Fix PDF and branding routes to use /api prefix

- Add /api prefix to PDF and branding route registration in server.ts
- Remove /api prefix from individual route definitions
- Fixes routing issue where PDF endpoints were not accessible through nginx

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
fullsizemalt 2026-01-08 19:13:35 -08:00
parent 978286606d
commit 4894679357
3 changed files with 13 additions and 13 deletions

View file

@ -20,7 +20,7 @@ const brandingSchema = z.object({
export async function brandingRoutes(fastify: FastifyInstance) {
// Get all branding configurations
fastify.get('/api/branding', async (request, reply) => {
fastify.get('/', async (request, reply) => {
try {
const brandings = brandingService.listBrandings();
reply.send({ brandings });
@ -30,7 +30,7 @@ export async function brandingRoutes(fastify: FastifyInstance) {
});
// Get a specific branding configuration
fastify.get<{ Params: { id: string } }>('/api/branding/:id', async (request, reply) => {
fastify.get<{ Params: { id: string } }>('/:id', async (request, reply) => {
try {
const { id } = request.params;
const branding = brandingService.getBranding(id);
@ -46,7 +46,7 @@ export async function brandingRoutes(fastify: FastifyInstance) {
});
// Create or update branding
fastify.post<{ Params: { id?: string } }>('/api/branding/:id?', async (request, reply) => {
fastify.post<{ Params: { id?: string } }>('/:id?', async (request, reply) => {
try {
const { id } = request.params;
const body = brandingSchema.parse(request.body);
@ -66,7 +66,7 @@ export async function brandingRoutes(fastify: FastifyInstance) {
});
// Delete branding
fastify.delete<{ Params: { id: string } }>('/api/branding/:id', async (request, reply) => {
fastify.delete<{ Params: { id: string } }>('/:id', async (request, reply) => {
try {
const { id } = request.params;
@ -83,7 +83,7 @@ export async function brandingRoutes(fastify: FastifyInstance) {
});
// Get default branding
fastify.get('/api/branding/default', async (request, reply) => {
fastify.get('/default', async (request, reply) => {
try {
const branding = brandingService.getDefaultBranding();
reply.send(branding);

View file

@ -38,7 +38,7 @@ const labelSchema = z.object({
export async function pdfRoutes(fastify: FastifyInstance) {
// Register a custom font for PDF generation
fastify.post('/api/pdf/fonts/register', async (request, reply) => {
fastify.post('/fonts/register', async (request, reply) => {
try {
const data = request.body as { name: string; fontData: string }; // base64 encoded font data
@ -66,7 +66,7 @@ export async function pdfRoutes(fastify: FastifyInstance) {
});
// List registered fonts
fastify.get('/api/pdf/fonts', async (request, reply) => {
fastify.get('/fonts', async (request, reply) => {
try {
const fonts = pdfService.getRegisteredFonts();
reply.send({ fonts });
@ -76,7 +76,7 @@ export async function pdfRoutes(fastify: FastifyInstance) {
});
// Generate a simple text PDF
fastify.post('/api/pdf/text', async (request, reply) => {
fastify.post('/text', async (request, reply) => {
try {
const body = textPDFSchema.parse(request.body)
const pdf = pdfService.generateTextPDF(body.content, body.options || { width: 612, height: 792, margin: 72 })
@ -91,7 +91,7 @@ export async function pdfRoutes(fastify: FastifyInstance) {
})
// Generate a certificate PDF
fastify.post('/api/pdf/certificate', async (request, reply) => {
fastify.post('/certificate', async (request, reply) => {
try {
const body = certificateSchema.parse(request.body)
const pdf = pdfService.generateCertificate(body)
@ -106,7 +106,7 @@ export async function pdfRoutes(fastify: FastifyInstance) {
})
// Generate a label PDF
fastify.post('/api/pdf/label', async (request, reply) => {
fastify.post('/label', async (request, reply) => {
try {
const body = labelSchema.parse(request.body)
const pdf = pdfService.generateLabel(body)
@ -121,7 +121,7 @@ export async function pdfRoutes(fastify: FastifyInstance) {
})
// Health check for PDF service
fastify.get('/api/pdf/health', async (request, reply) => {
fastify.get('/health', async (request, reply) => {
reply.send({
status: 'ok',
service: 'tinypdf-plus',

View file

@ -75,8 +75,8 @@ server.register(plantRoutes, { prefix: '/api/plants' });
// PDF generation
import { pdfRoutes } from './routes/pdf.routes';
import { brandingRoutes } from './routes/branding.routes';
server.register(pdfRoutes);
server.register(brandingRoutes);
server.register(pdfRoutes, { prefix: '/api/pdf' });
server.register(brandingRoutes, { prefix: '/api/branding' });
// Phase 10: Compliance
import { auditRoutes } from './routes/audit.routes';