generated from drivly/worker.templates.do
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
40 lines (34 loc) · 1.24 KB
/
worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
export const api = {
icon: '🚀',
name: 'templates.do',
description: 'Cloudflare Worker Template',
url: 'https://templates.do/api',
type: 'https://apis.do/templates',
endpoints: {
listCategories: 'https://templates.do/api',
getCategory: 'https://templates.do/:type',
},
site: 'https://templates.do',
login: 'https://templates.do/login',
signup: 'https://templates.do/signup',
subscribe: 'https://templates.do/subscribe',
repo: 'https://github.com/drivly/templates.do',
}
export const gettingStarted = [
`If you don't already have a JSON Viewer Browser Extension, get that first:`,
`https://extensions.do`,
]
export const examples = {
listItems: 'https://templates.do/worker',
}
export default {
fetch: async (req, env) => {
const { user, hostname, pathname, rootPath, pathSegments, query } = await env.CTX.fetch(req).then(res => res.json())
if (rootPath) return json({ api, gettingStarted, examples, user })
// TODO: Implement this
const [ resource, id ] = pathSegments
const data = { resource, id, hello: user.city }
return json({ api, data, user })
}
}
const json = obj => new Response(JSON.stringify(obj, null, 2), { headers: { 'content-type': 'application/json; charset=utf-8' }})