mirror of
https://github.com/Lissy93/web-check.git
synced 2025-01-25 07:38:37 +01:00
Starts making middleware functionality
This commit is contained in:
parent
65ff004b63
commit
f0ff33e081
29
api/_common/middleware.js
Normal file
29
api/_common/middleware.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
const normalizeUrl = (url) => {
|
||||||
|
// Normalizing logic here
|
||||||
|
return url.startsWith('http') ? url : `http://${url}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const commonMiddleware = (handler) => {
|
||||||
|
return async (event, context, callback) => {
|
||||||
|
try {
|
||||||
|
const rawUrl = event.queryStringParameters.url;
|
||||||
|
const url = normalizeUrl(rawUrl);
|
||||||
|
|
||||||
|
// Call the specific handler with the normalized URL
|
||||||
|
const response = await handler(url, event, context);
|
||||||
|
|
||||||
|
callback(null, {
|
||||||
|
statusCode: 200,
|
||||||
|
body: JSON.stringify(response),
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
callback(null, {
|
||||||
|
statusCode: 500,
|
||||||
|
body: JSON.stringify({ error: error.message }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = commonMiddleware;
|
Loading…
Reference in New Issue
Block a user