-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
48 lines (38 loc) · 1.28 KB
/
index.ts
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
41
42
43
44
45
46
47
48
import { Hono } from 'hono'
import { logger } from 'hono/logger'
import { serve } from '@hono/node-server'
import { readHomeTimeline, readUserTimeline, readMentions, readTweet, postTweet } from '@/actions/twitter'
const app = new Hono()
app.use(logger())
app.get('/home_timeline', async (ctx) => {
const tweets = await readHomeTimeline()
return ctx.json(tweets)
})
app.get('/user/:screen_name', async (ctx) => {
const { screen_name } = ctx.req.param()
const tweets = await readUserTimeline({ screen_name })
return ctx.json(tweets)
})
app.get('/mentions', async (ctx) => {
const tweets = await readMentions()
return ctx.json(tweets)
})
app.get('/user/:screen_name/:tweet_id', async (ctx) => {
const { screen_name, tweet_id } = ctx.req.param()
const tweet = await readTweet({ screen_name, tweet_id })
return ctx.json(tweet)
})
app.get('/user/:screen_name/status/:tweet_id', async (ctx) => {
const { screen_name, tweet_id } = ctx.req.param()
const tweet = await readTweet({ screen_name, tweet_id })
return ctx.json(tweet)
})
app.post('/tweets', async (ctx) => {
const { text } = await ctx.req.json()
await postTweet({ text: text as string })
return ctx.json({ "success": true })
})
serve({
fetch: app.fetch,
port: process.env.PORT ? parseInt(process.env.PORT) : 3000,
})