Image upload functionality
This commit is contained in:
@@ -9,6 +9,7 @@ import { dirname } from 'path';
|
||||
import dotenv from 'dotenv';
|
||||
import authRoutes from './routes/auth.js';
|
||||
import postRoutes from './routes/posts.js';
|
||||
import imageRoutes from './routes/images.js';
|
||||
|
||||
// Load environment variables
|
||||
dotenv.config();
|
||||
@@ -17,15 +18,7 @@ const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
const app = Fastify({
|
||||
logger: true,
|
||||
ajv: {
|
||||
customOptions: {
|
||||
removeAdditional: false,
|
||||
useDefaults: true,
|
||||
coerceTypes: true,
|
||||
allErrors: true
|
||||
}
|
||||
}
|
||||
logger: true
|
||||
});
|
||||
|
||||
// Register plugins
|
||||
@@ -37,16 +30,25 @@ await app.register(jwt, {
|
||||
secret: process.env.JWT_SECRET || 'your-super-secret-key-change-this-in-production'
|
||||
});
|
||||
|
||||
await app.register(multipart);
|
||||
await app.register(multipart, {
|
||||
limits: {
|
||||
fileSize: 5 * 1024 * 1024 // 5MB
|
||||
}
|
||||
});
|
||||
|
||||
await app.register(fastifyStatic, {
|
||||
root: join(__dirname, '../uploads'),
|
||||
prefix: '/uploads/'
|
||||
});
|
||||
|
||||
// Create uploads directory if it doesn't exist
|
||||
import { mkdirSync } from 'fs';
|
||||
mkdirSync(join(__dirname, '../uploads'), { recursive: true });
|
||||
|
||||
// Register routes
|
||||
await app.register(authRoutes);
|
||||
await app.register(postRoutes);
|
||||
await app.register(imageRoutes);
|
||||
|
||||
// Start the server
|
||||
const start = async () => {
|
||||
|
||||
Reference in New Issue
Block a user