Commit 7375b134 by Farhaan Khan

fastify api

parent 00fd08ff
...@@ -7,7 +7,13 @@ const app = Fastify(); ...@@ -7,7 +7,13 @@ const app = Fastify();
app.register(db); app.register(db);
app.register(userRoutes, { prefix: '/api/users' }); app.register(userRoutes, { prefix: '/api/users' });
app.get('/', async (request, reply) => {
return { message: 'Fastify server is running!' };
});
app.listen({ port: 3001 }, (err) => { app.listen({ port: 3001 }, (err) => {
if (err) throw err; if (err) throw err;
console.log('Server running on http://localhost:3001'); console.log('Server running on http://localhost:3001');
}); });
...@@ -8,14 +8,13 @@ const dbPlugin: FastifyPluginAsync = async (fastify) => { ...@@ -8,14 +8,13 @@ const dbPlugin: FastifyPluginAsync = async (fastify) => {
password: 'Faruskhan@985', password: 'Faruskhan@985',
host: 'localhost', host: 'localhost',
dialect: 'mysql', dialect: 'mysql',
models: [__dirname + '/../models'], // Make sure this path is correct models: [__dirname + '/../models'],
}); });
try { try {
await sequelize.sync(); await sequelize.sync();
console.log('Sequelize connected successfully'); console.log('Sequelize connected successfully');
// Optionally attach sequelize instance to Fastify
fastify.decorate('sequelize', sequelize); fastify.decorate('sequelize', sequelize);
} catch (err) { } catch (err) {
console.error('Error connecting to DB:', 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