-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
129 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import axios from "axios"; | ||
import { Request, Response, NextFunction } from "express"; | ||
|
||
const auth = async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
if (!req.headers.authorization) { | ||
return res.status(401).json({ message: "Unauthorized" }); | ||
} | ||
|
||
next(); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
const middleware = { | ||
auth, | ||
}; | ||
|
||
export default middleware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { hostname } from "os"; | ||
import { Express, Request, Response } from "express"; | ||
import config from "@/config.json"; | ||
import axios from "axios"; | ||
import middlewares from "@/middlewares"; | ||
|
||
export const createHandler = ( | ||
hostname: string, | ||
path: string, | ||
method: string | ||
) => { | ||
return async (req: Request, res: Response) => { | ||
try { | ||
let url = `${hostname}${path}`; | ||
|
||
console.log(url); | ||
|
||
req.params && | ||
Object.keys(req.params).forEach((key) => { | ||
url = url.replace(`:${key}`, req.params[key]); | ||
}); | ||
|
||
const { data } = await axios({ | ||
method, | ||
url, | ||
data: req.body, | ||
headers: { | ||
origin: "http://localhost:8080", | ||
"Content-Type": "application/json", | ||
"Access-Control-Allow-Origin": "*", | ||
}, | ||
}); | ||
|
||
res.status(200).json({ | ||
success: true, | ||
data, | ||
}); | ||
} catch (error) { | ||
console.log(error); | ||
if (error instanceof axios.AxiosError) { | ||
res.status(error.response?.status || 500).json({ | ||
success: false, | ||
error: error.response?.data?.message || error.message, | ||
}); | ||
} | ||
return res.status(500).json({ | ||
success: false, | ||
messages: "Something went wrong", | ||
}); | ||
} | ||
}; | ||
}; | ||
|
||
export const getMiddlewares = (names: string[]) => { | ||
return names.map((name) => middlewares[name]); | ||
}; | ||
|
||
export const configureRoutes = (app: Express) => { | ||
Object.entries(config.services).forEach(([_name, services]) => { | ||
const hostname = services.url; | ||
services.routes.forEach((route) => { | ||
route.methods.forEach((method) => { | ||
const endpoint = `/api${route.path}`; | ||
const middleware = getMiddlewares(route.middlewares); | ||
const handler = createHandler(hostname, route.path, method); | ||
app[method](endpoint, ...middleware, handler); | ||
}); | ||
}); | ||
}); | ||
}; |
51 changes: 0 additions & 51 deletions
51
packages/services/adoption/prisma/migrations/20240420201857_init/migration.sql
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
packages/services/adoption/prisma/migrations/migration_lock.toml
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
packages/services/auth/prisma/migrations/20240419182953_init/migration.sql
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
packages/services/user/prisma/migrations/20240420191253_iniy/migration.sql
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters