-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathoffload.ts
More file actions
52 lines (41 loc) · 1.41 KB
/
Copy pathoffload.ts
File metadata and controls
52 lines (41 loc) · 1.41 KB
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
49
50
51
52
import { Context, Hono } from 'hono'
import { generate, respondAlternative } from './generate'
import generateActivity from './util/generateActivity'
const app = new Hono()
const PORT = process.env.PORT ? parseInt(process.env.PORT) : 8787
const firstStart = Date.now()
export const logMiddleware = () => async (c: Context, next: () => Promise<void>) => {
const url = c.req.url
const userAgent = c.req.header('User-Agent') || 'Unknown'
const startTime = Date.now()
await next()
const endTime = Date.now()
const duration = endTime - startTime
const status = c.res.status
console.log(`[${new Date().toISOString()}] ${c.req.method} ${url} ${status} ${duration}ms - User-Agent: ${userAgent}`)
}
app.use('*', logMiddleware())
app.get('/', () => {
return new Response(
JSON.stringify({
message: 'fxTikTok offload server is running!',
github: 'https://github.com/okdargy/fxTikTok',
uptime: Date.now() - firstStart
}),
{
status: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Cache-Control': 'public, max-age=3600'
}
}
)
})
app.get('/api/v1/statuses/:videoId', async (c) => respondAlternative(c))
app.get('/users/:username/statuses/:videoId', async (c) => respondAlternative(c))
app.route('/generate', generate)
export default {
port: PORT,
fetch: app.fetch
}
console.log(`fxTikTok offload server is running on port ${PORT}`)