๐Ÿ“ฆ sglkc / tts-api

๐Ÿ“„ api.js ยท 25 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25import Fastify from 'fastify'
import main from './index.js'

const app = Fastify()

app.route({
  method: ['GET', 'POST'],
  url: '/',
  handler: async (req) => {
    let body = req.body

    if (typeof body === 'string') {
      try { body = JSON.parse(req.body) } catch (e) {}
    }

    const payload = Object.assign({}, body, req.query)

    return await main(payload)
  }
})

app.listen({ port: process.env.PORT || 3000 })
  .then(console.log)
  .catch(console.error)