π A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!
Vue awesomedashboarddockerhomelabhomepagemitnodejsorganizationproductivitypwaself-hostedstartpagevue
:art: Updates how headers are applied to Netlify CORS proxy
Alicia Sykes6e310628f718
diff --git a/services/serverless-functions/netlify-cors.js b/services/serverless-functions/netlify-cors.jsindex eaa7b4b7..3789238e 100644--- a/services/serverless-functions/netlify-cors.js+++ b/services/serverless-functions/netlify-cors.js@@ -2,41 +2,47 @@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 = event.queryStringParameters.url- || event.headers['Target-URL']- || event.headers['target-url'];+ const requestUrl = queryStringParameters.url || headers['Target-URL'] || headers['target-url'];- // If URL missing, return error- if (!requestUrl) {+ const returnError = (msg, error) => {callback(null, {statusCode: 400,- body: JSON.stringify({ success: false, msg: 'Missing Target-URL header' }),+ 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 requestconst requestConfig = {method: 'GET',url: requestUrl,- json: event.body,- };-- // Response headers- const headers = {- 'Access-Control-Allow-Origin': '*',- ...event.headers,+ json: body,+ headers: requestHeaders,};// Make requestaxios.request(requestConfig).then((response) => {- const body = JSON.stringify(response.data);- callback(null, { statusCode: 200, body, headers });+ callback(null, { statusCode: 200, body: JSON.stringify(response.data) });}).catch((error) => {- callback(null, {- statusCode: 400,- body: JSON.stringify({ success: false, msg: 'Request failed', error }),- });+ returnError('Request failed', error);});};