mirror of https://github.com/lissy93/dashy
✨ Adds Netlify support for proxying CORS requests
This commit is contained in:
parent
7f968a708a
commit
e3f2b910ec
90
netlify.toml
90
netlify.toml
|
@ -1,42 +1,48 @@
|
||||||
# Enables you to easily deploy a fork of Dashy to Netlify
|
# Enables you to easily deploy a fork of Dashy to Netlify
|
||||||
# without the need to configure anything in admin UI
|
# without the need to configure anything in admin UI
|
||||||
# Docs: https://www.netlify.com/docs/netlify-toml-reference/
|
# Docs: https://www.netlify.com/docs/netlify-toml-reference/
|
||||||
|
|
||||||
# Essential site config
|
# Essential site config
|
||||||
[build]
|
[build]
|
||||||
base = "/"
|
base = "/"
|
||||||
command = "yarn build"
|
command = "yarn build"
|
||||||
publish = "dist"
|
publish = "dist"
|
||||||
functions = "services/serverless-functions"
|
functions = "services/serverless-functions"
|
||||||
|
|
||||||
# Site info, used for the 1-Click deploy page
|
# Site info, used for the 1-Click deploy page
|
||||||
[template.environment]
|
[template.environment]
|
||||||
STATUSKIT_PAGE_TITLE = "Dashy"
|
STATUSKIT_PAGE_TITLE = "Dashy"
|
||||||
STATUSKIT_COMPANY_LOGO = "https://raw.githubusercontent.com/Lissy93/dashy/master/docs/assets/logo.png"
|
STATUSKIT_COMPANY_LOGO = "https://raw.githubusercontent.com/Lissy93/dashy/master/docs/assets/logo.png"
|
||||||
STATUSKIT_SUPPORT_CONTACT_LINK = "https://github.com/lissy93/dashy"
|
STATUSKIT_SUPPORT_CONTACT_LINK = "https://github.com/lissy93/dashy"
|
||||||
STATUSKIT_RESOURCES_LINK = "https://dashy.to/docs"
|
STATUSKIT_RESOURCES_LINK = "https://dashy.to/docs"
|
||||||
|
|
||||||
# Redirect the Node endpoints to serverless functions
|
# Redirect the Node endpoints to serverless functions
|
||||||
[[redirects]]
|
[[redirects]]
|
||||||
from = "/status-check"
|
from = "/status-check"
|
||||||
to = "/.netlify/functions/cloud-status-check"
|
to = "/.netlify/functions/cloud-status-check"
|
||||||
status = 301
|
status = 301
|
||||||
force = true
|
force = true
|
||||||
[[redirects]]
|
[[redirects]]
|
||||||
from = "/config-manager/*"
|
from = "/config-manager/*"
|
||||||
to = "/.netlify/functions/not-supported"
|
to = "/.netlify/functions/not-supported"
|
||||||
status = 301
|
status = 301
|
||||||
force = true
|
force = true
|
||||||
|
[[redirects]]
|
||||||
# For router history mode, ensure pages land on index
|
from = "/cors-proxy"
|
||||||
[[redirects]]
|
to = "/.netlify/functions/netlify-cors"
|
||||||
from = "/*"
|
status = 301
|
||||||
to = "/index.html"
|
force = true
|
||||||
status = 200
|
|
||||||
|
# For router history mode, ensure pages land on index
|
||||||
# Set any security headers here
|
[[redirects]]
|
||||||
[[headers]]
|
from = "/*"
|
||||||
for = "/*"
|
to = "/index.html"
|
||||||
[headers.values]
|
status = 200
|
||||||
# Uncomment to enable Netlify user control. You must have a paid plan.
|
|
||||||
# Basic-Auth = "someuser:somepassword anotheruser:anotherpassword"
|
# Set any security headers here
|
||||||
|
[[headers]]
|
||||||
|
for = "/*"
|
||||||
|
[headers.values]
|
||||||
|
# Uncomment to enable Netlify user control. You must have a paid plan.
|
||||||
|
# Basic-Auth = "someuser:somepassword anotheruser:anotherpassword"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/* A Netlify cloud function to handle requests to CORS-disabled services */
|
||||||
|
const axios = require('axios');
|
||||||
|
|
||||||
|
exports.handler = (event, context, callback) => {
|
||||||
|
// Get URL from header or GET param
|
||||||
|
const requestUrl = event.queryStringParameters.url
|
||||||
|
|| event.headers['Target-URL']
|
||||||
|
|| event.headers['target-url'];
|
||||||
|
|
||||||
|
// If URL missing, return error
|
||||||
|
if (!requestUrl) {
|
||||||
|
callback(null, {
|
||||||
|
statusCode: 400,
|
||||||
|
body: JSON.stringify({ success: false, msg: 'Missing Target-URL header' }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare request
|
||||||
|
const requestConfig = {
|
||||||
|
method: 'GET',
|
||||||
|
url: requestUrl,
|
||||||
|
json: event.body,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Response headers
|
||||||
|
const headers = {
|
||||||
|
'Access-Control-Allow-Origin': '*',
|
||||||
|
...event.headers,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Make request
|
||||||
|
axios.request(requestConfig)
|
||||||
|
.then((response) => {
|
||||||
|
const body = JSON.stringify(response.data);
|
||||||
|
callback(null, { statusCode: 200, body, headers });
|
||||||
|
}).catch((error) => {
|
||||||
|
callback(null, {
|
||||||
|
statusCode: 400,
|
||||||
|
body: JSON.stringify({ success: false, msg: 'Request failed', error }),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
Loading…
Reference in New Issue