first commit

This commit is contained in:
2024-05-02 07:42:34 +07:00
commit 61922abab7
405 changed files with 104316 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
/* A cloud function that wraps the status checking method, for use on Netlify */
const statusCheck = require('../status-check');
exports.handler = (event, context, callback) => {
const paramStr = event.rawQuery;
statusCheck(paramStr, (results) => {
callback(null, {
statusCode: 200,
body: results,
});
});
};

View File

@@ -0,0 +1,48 @@
/* A Netlify cloud function to handle requests to CORS-disabled services */
const axios = require('axios');
exports.handler = (event, context, callback) => {
// Get input data
const { body, headers, queryStringParameters } = event;
// Get URL from header or GET param
const requestUrl = queryStringParameters.url || headers['Target-URL'] || headers['target-url'];
const returnError = (msg, error) => {
callback(null, {
statusCode: 400,
body: JSON.stringify({ success: false, msg, error }),
});
};
// If URL missing, return error
if (!requestUrl) {
returnError('Missing Target-URL header', null);
}
let custom = {};
try {
custom = JSON.parse(headers.CustomHeaders || headers.customheaders || '{}');
} catch (e) { returnError('Unable to parse custom headers'); }
// Response headers
const requestHeaders = {
'Access-Control-Allow-Origin': '*',
...custom,
};
// Prepare request
const requestConfig = {
method: 'GET',
url: requestUrl,
json: body,
headers: requestHeaders,
};
// Make request
axios.request(requestConfig)
.then((response) => {
callback(null, { statusCode: 200, body: JSON.stringify(response.data) });
}).catch((error) => {
returnError('Request failed', error);
});
};

View File

@@ -0,0 +1,8 @@
/* A Netlify cloud function to return a message endpoints that are not available */
exports.handler = async () => ({
statusCode: 200,
body: JSON.stringify({
success: false,
error: 'This action is not supported on Netlify',
}),
});