-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (31 loc) · 1.02 KB
/
index.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
import { Router } from 'itty-router'
import thanks from './_layouts/thanks'
const router = Router()
router.get('/apply', async (req) => {
return new Response(null, {
status: 302,
headers: {
location: "/login?redirect_uri=" + new URL(req.url).origin + "/thanks",
}
})
})
router.get('/thanks', async (req, env) => {
const { user } = await env.CTX.fetch(req).then(res => res.json())
if (!user.authenticated) {
return new Response(null, {
status: 302,
headers: {
location: '/',
}
})
}
let githubUser = await env.USERS.get(user.id).then(JSON.parse)
await fetch(env.SLACK_WEBHOOK_URL, { method: 'POST', body: JSON.stringify({ icon_url: user.image, text: `careers.do just collected a new candidate!\n${user.name}\n${githubUser.user.html_url}\n${githubUser.user.email}` }) })
return new Response(thanks(user.name, user.image), {
headers: { 'content-type': 'text/html; charset=utf-8' }
})
})
router.get('*', req => fetch(req))
export default {
fetch: router.handle
}