1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-11-24 04:31:31 +03:00

refactor(server): rename over HTTP option toggle

This commit is contained in:
louistiti 2022-02-02 19:52:41 +08:00
parent 5c88c134f4
commit f61eef4882
No known key found for this signature in database
GPG Key ID: 0A1C3B043E70C77D
2 changed files with 23 additions and 23 deletions

View File

@ -25,7 +25,7 @@ LEON_TTS=false
LEON_TTS_PROVIDER=flite
# Enable/disable packages to be available over HTTP
LEON_PACKAGES_OVER_HTTP=true
LEON_OVER_HTTP=true
# HTTP API key (use "npm run generate:http-api-key" to regenerate one)
LEON_HTTP_API_KEY=

View File

@ -226,34 +226,34 @@ const bootstrap = async () => {
fastify.register(infoPlugin, { apiVersion })
fastify.register(downloadsPlugin, { apiVersion })
fastify.register((instance, opts, next) => {
instance.addHook('preHandler', keyMidd)
if (process.env.LEON_OVER_HTTP === 'true') {
fastify.register((instance, opts, next) => {
instance.addHook('preHandler', keyMidd)
instance.post('/core/query', async (request, reply) => {
const { query } = request.body
instance.post('/api/core/query', async (request, reply) => {
const { query } = request.body
try {
const data = await nlu.process(query, { mute: true })
try {
const data = await nlu.process(query, { mute: true })
reply.send({
...data,
success: true
})
} catch (e) {
reply.statusCode = 500
reply.send({
message: e.message,
success: false
})
}
})
reply.send({
...data,
success: true
})
} catch (e) {
reply.statusCode = 500
reply.send({
message: e.message,
success: false
})
}
})
if (process.env.LEON_PACKAGES_OVER_HTTP === 'true') {
generatePackagesRoutes(instance)
}
next()
})
next()
})
}
httpServer = fastify.server