diff --git a/Justfile b/Justfile index 3d0543c..f1a0830 100644 --- a/Justfile +++ b/Justfile @@ -9,7 +9,7 @@ user: fastify start src/api/user/default.js apis: - node dev.js + node src/dev.js front: vite diff --git a/dev.js b/dev.js index 7e2ef10..a0ab584 100644 --- a/dev.js +++ b/dev.js @@ -1,6 +1,6 @@ import Fastify from 'fastify'; -import authApi from './src/api/auth/default.js'; -import userApi from './src/api/user/default.js'; +import authApi from './api/auth/default.js'; +import userApi from './api/user/default.js'; const loggerOption = { transport: { diff --git a/src/api/user/default.js b/src/api/user/default.js index 8c06324..990da7e 100644 --- a/src/api/user/default.js +++ b/src/api/user/default.js @@ -122,10 +122,12 @@ export default async function(fastify, options) { // POST fastify.post('/users/:userId', { preHandler: [fastify.authenticateAdmin] }, async (request, reply) => { try { + const userId = request.params.userId; + if (getUserInfo.get(userId)) { return reply.code(400).send({ error: "User already exist" }); } - createUser.run(request.params.userId, request.params.userId); + createUser.run(userId, userId); return reply.code(200).send({ msg: "User created sucessfully" }); } catch (err) { fastify.log.error(err); diff --git a/src/dev.js b/src/dev.js new file mode 100644 index 0000000..a0ab584 --- /dev/null +++ b/src/dev.js @@ -0,0 +1,32 @@ +import Fastify from 'fastify'; +import authApi from './api/auth/default.js'; +import userApi from './api/user/default.js'; + +const loggerOption = { + transport: { + target: 'pino-pretty', + options: { + colorize: true, + translateTime: 'HH:MM:ss', + ignore: 'pid,hostname' + } + } +}; + +async function start() { + const auth = Fastify({ + logger: loggerOption + }); + auth.register(authApi); + await auth.listen({ port: 3001 }); + console.log('Auth API listening on http://localhost:3001'); + + const user = Fastify({ + logger: loggerOption + }); + user.register(userApi); + await user.listen({ port: 3002 }); + console.log('User data API listening on http://localhost:3002'); +} + +start().catch(console.error); diff --git a/tailwind.config.js b/tailwind.config.js new file mode 100644 index 0000000..d2fdab4 --- /dev/null +++ b/tailwind.config.js @@ -0,0 +1,7 @@ +export default { + content: ['./src/front/**/*.{html,js}'], + theme: { + extend: {}, + }, + plugins: [], +}