Skip to content

Commit

Permalink
added README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkirathe committed Sep 4, 2024
1 parent 36ab1c5 commit 3af0c2d
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions netlify/functions/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*
import express from 'express';
import jwt from 'jsonwebtoken';
import morgan from 'morgan';
Expand All @@ -7,7 +6,7 @@ import swaggerUi from 'swagger-ui-express';
import swaggerJsdoc from 'swagger-jsdoc';
import { Server } from 'socket.io';
import http from 'http';
import { swaggerOptions } from '../swaggerConfig.js';
import { swaggerOptions } from 'swaggerConfig.js';

const index = express();
const port = 3500;
Expand Down Expand Up @@ -45,7 +44,7 @@ const generateTokens = (user) => {
const specs = swaggerJsdoc(swaggerOptions);
index.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs));

/!**
/**
* @swagger
* /api/signin:
* post:
Expand All @@ -66,7 +65,7 @@ index.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs));
* description: Successful sign in
* 401:
* description: Invalid email or password
*!/
*/
index.post('/api/signin', (req, res) => {
const { email, password } = req.body;
const user = users.find((u) => u.email === email && u.password === password);
Expand All @@ -79,7 +78,7 @@ index.post('/api/signin', (req, res) => {
}
});

/!**
/**
* @swagger
* /api/signup:
* post:
Expand All @@ -100,7 +99,7 @@ index.post('/api/signin', (req, res) => {
* description: User created successfully
* 409:
* description: User already exists
*!/
*/
index.post('/api/signup', (req, res) => {
const { email, password } = req.body;
const userExists = users.some((u) => u.email === email);
Expand All @@ -115,7 +114,7 @@ index.post('/api/signup', (req, res) => {
}
});

/!**
/**
* @swagger
* /api/user:
* get:
Expand All @@ -129,7 +128,7 @@ index.post('/api/signup', (req, res) => {
* description: Invalid token
* 404:
* description: User not found
*!/
*/
index.get('/api/user', (req, res) => {
const authHeader = req.headers.authorization;
if (!authHeader) {
Expand All @@ -150,7 +149,7 @@ index.get('/api/user', (req, res) => {
}
});

/!**
/**
* @swagger
* /api/refresh:
* post:
Expand All @@ -169,7 +168,7 @@ index.get('/api/user', (req, res) => {
* description: Token refreshed successfully
* 401:
* description: Invalid refresh token
*!/
*/
index.post('/api/refresh', (req, res) => {
const { refreshToken } = req.body;
try {
Expand All @@ -186,38 +185,38 @@ index.post('/api/refresh', (req, res) => {
}
});

/!**
/**
* @swagger
* /api/check:
* get:
* summary: Check if the server is working
* responses:
* 200:
* description: Server is working
*!/
*/
index.get('/api/check', (req, res) => {
res.status(200).json({ message: 'All working' });
});

/!**
/**
* @swagger
* /api/users:
* get:
* summary: Get all users
* responses:
* 200:
* description: List of users retrieved successfully
*!/
*/
index.get('/api/users', (req, res) => {
res.status(200).json({ users });
});

server.listen(port, () => {
console.log(`Mock API server running at http://localhost:${port}`);
});
*/


/*
import express, { Router } from "express";
import serverless from "serverless-http";
Expand All @@ -228,4 +227,4 @@ router.get("/hello", (req, res) => res.send("Hello World!"));
api.use("/api/", router);
export const handler = serverless(api);
export const handler = serverless(api);*/

0 comments on commit 3af0c2d

Please sign in to comment.