Commit 7375b134 by Farhaan Khan

fastify api

parent 00fd08ff
......@@ -7,7 +7,13 @@ const app = Fastify();
app.register(db);
app.register(userRoutes, { prefix: '/api/users' });
app.get('/', async (request, reply) => {
return { message: 'Fastify server is running!' };
});
app.listen({ port: 3001 }, (err) => {
if (err) throw err;
console.log('Server running on http://localhost:3001');
});
......@@ -8,14 +8,13 @@ const dbPlugin: FastifyPluginAsync = async (fastify) => {
password: 'Faruskhan@985',
host: 'localhost',
dialect: 'mysql',
models: [__dirname + '/../models'], // Make sure this path is correct
models: [__dirname + '/../models'],
});
try {
await sequelize.sync();
console.log('Sequelize connected successfully');
// Optionally attach sequelize instance to Fastify
fastify.decorate('sequelize', sequelize);
} catch (err) {
console.error('Error connecting to DB:', err);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment