mirror of
https://github.com/leon-ai/leon.git
synced 2025-01-03 22:28:10 +03:00
refactor(server): make use of consts for HTTP API matters
This commit is contained in:
parent
d05d572b70
commit
819e57a2c2
@ -24,3 +24,7 @@ export const HAS_STT = process.env['LEON_STT'] === 'true'
|
||||
export const STT_PROVIDER = process.env['LEON_STT_PROVIDER']
|
||||
export const HAS_TTS = process.env['LEON_TTS'] === 'true'
|
||||
export const TTS_PROVIDER = process.env['LEON_TTS_PROVIDER']
|
||||
|
||||
export const HAS_OVER_HTTP = process.env['LEON_OVER_HTTP'] === 'true'
|
||||
export const HTTP_API_KEY = process.env['LEON_HTTP_API_KEY']
|
||||
export const HTTP_API_LANG = process.env['LEON_HTTP_API_LANG']
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { HTTP_API_KEY } from '@/constants'
|
||||
|
||||
const keyMidd = async (request, reply) => {
|
||||
const apiKey = request.headers['x-api-key']
|
||||
if (!apiKey || apiKey !== process.env.LEON_HTTP_API_KEY) {
|
||||
if (!apiKey || apiKey !== HTTP_API_KEY) {
|
||||
reply.statusCode = 401
|
||||
reply.send({
|
||||
message: 'Unauthorized, please check the HTTP API key is correct',
|
||||
|
@ -6,6 +6,7 @@ import { join } from 'path'
|
||||
import { version } from '@@/package.json'
|
||||
import { endpoints } from '@@/core/skills-endpoints.json'
|
||||
import {
|
||||
HAS_OVER_HTTP,
|
||||
HAS_STT,
|
||||
HAS_TTS,
|
||||
HOST,
|
||||
@ -327,7 +328,7 @@ server.bootstrap = async () => {
|
||||
server.fastify.register(infoPlugin, { apiVersion })
|
||||
server.fastify.register(downloadsPlugin, { apiVersion })
|
||||
|
||||
if (process.env.LEON_OVER_HTTP === 'true') {
|
||||
if (HAS_OVER_HTTP) {
|
||||
server.fastify.register((instance, opts, next) => {
|
||||
instance.addHook('preHandler', keyMidd)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user