Skip to content

Commit cf5f723

Browse files
authored
🔀 Merge pull request #235 from Lissy93/FEATURE/serverless-functions
[FEATURE] Serverless Functions for CDN Deploys
2 parents 5c38c6f + cd03678 commit cf5f723

File tree

7 files changed

+153
-55
lines changed

7 files changed

+153
-55
lines changed

.github/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## ✨ 1.8.2 - Serverless Functions for Netlify Instances [PR #235](https://github.com/Lissy93/dashy/pull/235)
4+
- Previously when Dashy was deployed as a static site to Netlify, it was not possible to use several features, which required server-side code
5+
- This PR adds serverless cloud functions to provide most of this functionality
6+
37
## 🩹 1.8.1 - Additional Languages, Bug Fix, and more [PR #234](https://github.com/Lissy93/dashy/pull/234)
48
- Merges 5 additional languages
59
- Adds RickyCZ's dashboard to showcase

docs/development-guides.md

+34
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,40 @@ Running `yarn upgrade` will updated all dependencies based on the ranges specifi
141141

142142
---
143143

144+
## Developing Netlify Cloud Functions
145+
146+
When Dashy is deployed to Netlify, it is effectively running as a static app, and therefore the server-side code for the Node.js endpoints is not available. However Netlify now supports serverless cloud lambda functions, which can be used to replace most functionality.
147+
148+
#### 1. Run Netlify Dev Server
149+
150+
First off, install the Netlify CLI: `npm install netlify-cli -g`
151+
Then, from within the root of Dashy's directory, start the server, by running: `netlify dev`
152+
153+
#### 2. Create a lambda function
154+
155+
This should be saved it in the [`./services/serverless-functions`](https://github.com/Lissy93/dashy/tree/master/services/serverless-functions) directory
156+
157+
```javascript
158+
exports.handler = async () => ({
159+
statusCode: 200,
160+
body: 'Return some data here...',
161+
});
162+
```
163+
164+
#### 3. Redirect the Node endpoint to the function
165+
166+
In the [`netlify.toml`](https://github.com/Lissy93/dashy/blob/FEATURE/serverless-functions/netlify.toml) file, add a 301 redirect, with the path to the original Node.js endpoint, and the name of your cloud function
167+
168+
```toml
169+
[[redirects]]
170+
from = "/status-check"
171+
to = "/.netlify/functions/cloud-status-check"
172+
status = 301
173+
force = true
174+
```
175+
176+
---
177+
144178
## Hiding Page Furniture on Certain Routes
145179
For some pages (such as the login page, the minimal start page, etc) the basic page furniture, (like header, footer, nav, etc) is not needed. This section explains how you can hide furniture on a new view (step 1), or add a component that should be hidden on certain views (step 2).
146180

docs/release-workflow.md

+77-50
Large diffs are not rendered by default.

netlify.toml

+17-4
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,30 @@
77
base = "/"
88
command = "yarn build"
99
publish = "dist"
10+
functions = "services/serverless-functions"
1011

1112
# Site info, used for the 1-Click deploy page
1213
[template.environment]
1314
STATUSKIT_PAGE_TITLE = "Dashy"
1415
STATUSKIT_COMPANY_LOGO = "https://raw.githubusercontent.com/Lissy93/dashy/master/docs/assets/logo.png"
15-
STATUSKIT_SUPPORT_CONTACT_LINK = "https://dashy.to"
16-
STATUSKIT_RESOURCES_LINK = "https://github.com/Lissy93/dashy/tree/master/docs"
17-
16+
STATUSKIT_SUPPORT_CONTACT_LINK = "https://github.com/lissy93/dashy"
17+
STATUSKIT_RESOURCES_LINK = "https://dashy.to/docs"
18+
19+
# Redirect the Node endpoints to serverless functions
20+
[[redirects]]
21+
from = "/status-check"
22+
to = "/.netlify/functions/cloud-status-check"
23+
status = 301
24+
force = true
25+
[[redirects]]
26+
from = "/config-manager/*"
27+
to = "/.netlify/functions/not-supported"
28+
status = 301
29+
force = true
30+
1831
# Set any security headers here
1932
[[headers]]
2033
for = "/*"
2134
[headers.values]
2235
# Uncomment to enable Netlify user control. You must have a paid plan.
23-
# Basic-Auth = "someuser:somepassword anotheruser:anotherpassword"
36+
# Basic-Auth = "someuser:somepassword anotheruser:anotherpassword"

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Dashy",
3-
"version": "1.8.1",
3+
"version": "1.8.2",
44
"license": "MIT",
55
"main": "server",
66
"scripts": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* A cloud function that wraps the status checking method, for use on Netlify */
2+
const statusCheck = require('../status-check');
3+
4+
exports.handler = (event, context, callback) => {
5+
const paramStr = event.rawQuery;
6+
statusCheck(paramStr, (results) => {
7+
callback(null, {
8+
statusCode: 200,
9+
body: results,
10+
});
11+
});
12+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* A Netlify cloud function to return a message endpoints that are not available */
2+
exports.handler = async () => ({
3+
statusCode: 200,
4+
body: JSON.stringify({
5+
success: false,
6+
error: 'This action is not supported on Netlify',
7+
}),
8+
});

0 commit comments

Comments
 (0)