diff --git a/netlify.toml b/netlify.toml index a5d5f7f..a9952a7 100644 --- a/netlify.toml +++ b/netlify.toml @@ -48,6 +48,16 @@ from = "/ssl-check" to = "/.netlify/functions/ssl-check" status = 301 + force = true +[[redirects]] + from = "/get-headers" + to = "/.netlify/functions/get-headers" + status = 301 + force = true +[[redirects]] + from = "/get-cookies" + to = "/.netlify/functions/get-cookies" + status = 301 force = true # For router history mode, ensure pages land on index diff --git a/server/lambda/get-cookies.js b/server/lambda/get-cookies.js new file mode 100644 index 0000000..ac12ae8 --- /dev/null +++ b/server/lambda/get-cookies.js @@ -0,0 +1,27 @@ +const fetch = require('node-fetch'); + +exports.handler = async function(event, context) { + const { url } = event.queryStringParameters; + + if (!url) { + return { + statusCode: 400, + body: JSON.stringify({ message: 'url query string parameter is required' }), + }; + } + + try { + const response = await fetch(url); + const cookies = response.headers.get('set-cookie'); + + return { + statusCode: 200, + body: JSON.stringify({ cookies }), + }; + } catch (error) { + return { + statusCode: 500, + body: JSON.stringify({ message: error.message }), + }; + } +}; diff --git a/server/lambda/get-headers.js b/server/lambda/get-headers.js new file mode 100644 index 0000000..f07eacc --- /dev/null +++ b/server/lambda/get-headers.js @@ -0,0 +1,27 @@ +const fetch = require('node-fetch'); + +exports.handler = async function(event, context) { + const { url } = event.queryStringParameters; + + if (!url) { + return { + statusCode: 400, + body: JSON.stringify({ message: 'url query string parameter is required' }), + }; + } + + try { + const response = await fetch(url); + const headers = response.headers.raw(); + + return { + statusCode: 200, + body: JSON.stringify(headers), + }; + } catch (error) { + return { + statusCode: 500, + body: JSON.stringify({ message: error.message }), + }; + } +};