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:
parent
5c88c134f4
commit
f61eef4882
@ -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=
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user