mirror of
https://github.com/Lissy93/web-check.git
synced 2025-05-17 20:50:46 +02:00
Writes server functions to get cookied and headers
This commit is contained in:
parent
b17c2f0b2d
commit
2adbd097a1
10
netlify.toml
10
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
|
||||
|
27
server/lambda/get-cookies.js
Normal file
27
server/lambda/get-cookies.js
Normal file
@ -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 }),
|
||||
};
|
||||
}
|
||||
};
|
27
server/lambda/get-headers.js
Normal file
27
server/lambda/get-headers.js
Normal file
@ -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 }),
|
||||
};
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user