feat(runkit): new url patterns, fix examples (#472)

* fix(runkit): new runkit example

https://runkit.com/amio/satisfaction endpoint stoped working due
to getsatisfaction.com shutdown

* feat(runkit): owner/notebook endpoints

Support both:
1. legacy `/runkit/:endpoint-id/:path*` URL patterns
2. new `/runkit/:owner/:notebook/:path*` URL patterns

Update documentation & examples to use new pattern.

* docs(runkit): update examples
pull/477/head
Dario Vladović 2021-01-08 04:27:34 +01:00 zatwierdzone przez GitHub
rodzic cde21008cb
commit cdaefa14ae
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 26 dodań i 21 usunięć

Wyświetl plik

@ -2,9 +2,12 @@ import got from '../libs/got'
import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler'
const help = `
https://badgen.net/runkit/cal-badge-icd0onfvrxx6/Asia/Shanghai
endpoint-id path-args (optional)
https://badgen.net/runkit/amio/cal-badge/Asia/Shanghai
path-args (optional)
notebook
owner
## RunKit Endpoint
@ -18,7 +21,7 @@ If you are not familiar with RunKit endpoint, [this guide](https://runkit.com/do
1. Create a RunKit notebook (e.g. https://runkit.com/amio/cal-badge), which gives you an endpoint:
\`\`\`
https://cal-badge-icd0onfvrxx6.runkit.sh
https://runkit.io/amio/cal-badge/branches/master
\`\`\`
it returns a JSON like:
@ -31,32 +34,28 @@ If you are not familiar with RunKit endpoint, [this guide](https://runkit.com/do
}
\`\`\`
2. Click <kbd>endpoint</kbd> on notebook page for the endpoint address, then you have \`endpoint-id\` from it's subdomain:
3. Construct badgen url using \`owner\` and \`notebook\` params:
\`\`\`
cal-badge-icd0onfvrxx6
\`\`\`
3. Use \`endpoint-id\` within badgen url:
\`\`\`
https://badgen.net/runkit/cal-badge-icd0onfvrxx6
https://badgen.net/runkit/amio/cal-badge
\`\`\`
That's it:
![](https://badgen.net/runkit/cal-badge-icd0onfvrxx6)
![](/runkit/amio/cal-badge)
Furthermore, you can append arbitrary path args (e.g. \`/Asia/Shanghai\`) to the end of badgen url, Badgen will request RunKit endpoint with that. This badge:
\`\`\`
https://badgen.net/runkit/cal-badge-icd0onfvrxx6/Asia/Shanghai
https://badgen.net/runkit/amio/cal-badge/Asia/Shanghai
\`\`\`
![](/runkit/amio/cal-badge/Asia/Shanghai)
represents data from:
\`\`\`
https://cal-badge-icd0onfvrxx6.runkit.sh/Asia/Shanghai
https://runkit.io/amio/cal-badge/branches/master/Asia/Shanghai
\`\`\`
`
@ -64,16 +63,22 @@ export default createBadgenHandler({
title: 'With RunKit Endpoint',
help,
examples: {
'/runkit/satisfaction-flq08o9mm3ka/102909/topic': 'satisfaction (topic)',
'/runkit/satisfaction-flq08o9mm3ka/102909/people': 'satisfaction (people)',
'/runkit/satisfaction-flq08o9mm3ka/102909/employee': 'satisfaction (employ)',
'/runkit/vladimyr/metaweather/44418/state': 'metaweather (state)',
'/runkit/vladimyr/metaweather/44418/temperature': 'metaweather (temperature in °C)',
'/runkit/vladimyr/metaweather/44418/temperature/f': 'metaweather (temperature in °F)',
'/runkit/vladimyr/metaweather/44418/wind': 'metaweather (wind in km/h)',
'/runkit/vladimyr/metaweather/44418/wind/mph': 'metaweather (wind in mph)',
'/runkit/vladimyr/metaweather/44418/humidity': 'metaweather (humidity)',
},
handlers: {
'/runkit/:endpoint-id/:path*': handler
'/runkit/:endpoint-id<.+-[a-z0-9]{12}>/:path*': handler, // legacy handler
'/runkit/:owner/:notebook/:path*': handler
}
})
async function handler ({ 'endpoint-id': id, path }: PathArgs) {
const endpoint = `https://${id}.runkit.sh/${path || ''}`
async function handler ({ 'endpoint-id': id, owner, notebook, path = '' }: PathArgs) {
const endpoint = id
? `https://${id}.runkit.sh/${path}`
: `https://runkit.io/${owner}/${notebook}/branches/master/${path}`
return await got(endpoint).json<any>()
}