mirror of
https://github.com/leon-ai/leon.git
synced 2024-11-28 04:04:58 +03:00
refactor: give a try for better reverse proxy
This commit is contained in:
parent
82a910b59b
commit
7c4403fdaf
@ -8,12 +8,12 @@ LEON_LANG=en-US
|
|||||||
LEON_NODE_ENV=development
|
LEON_NODE_ENV=development
|
||||||
|
|
||||||
# Server
|
# Server
|
||||||
LEON_SERVER_HOST=localhost
|
LEON_SERVER_HOST=http://localhost
|
||||||
LEON_SERVER_PORT=1337
|
LEON_SERVER_PORT=1337
|
||||||
|
|
||||||
# Web app
|
# Web app
|
||||||
LEON_WEBAPP_HOST=localhost
|
LEON_WEBAPP_HOST=http://localhost
|
||||||
LEON_WEBAPP_PORT=4242
|
LEON_WEBAPP_PORT=1337
|
||||||
|
|
||||||
# Time zone (current one by default)
|
# Time zone (current one by default)
|
||||||
LEON_TIME_ZONE=
|
LEON_TIME_ZONE=
|
||||||
|
@ -8,7 +8,7 @@ export default class Client {
|
|||||||
this.host = host
|
this.host = host
|
||||||
this.port = port
|
this.port = port
|
||||||
this._input = input
|
this._input = input
|
||||||
this.socket = io.connect(`http://${this.host}:${this.port}`)
|
this.socket = io.connect(`${this.host}:${this.port}`)
|
||||||
this.history = localStorage.getItem('history')
|
this.history = localStorage.getItem('history')
|
||||||
this.parsedHistory = []
|
this.parsedHistory = []
|
||||||
this.info = res
|
this.info = res
|
||||||
@ -58,7 +58,7 @@ export default class Client {
|
|||||||
})
|
})
|
||||||
|
|
||||||
this.socket.on('download', (data) => {
|
this.socket.on('download', (data) => {
|
||||||
window.location = `http://${config.server_host}:${config.server_port}/v1/downloads?package=${data.package}&module=${data.module}`
|
window.location = `${config.server_host}:${config.server_port}/v1/downloads?package=${data.package}&module=${data.module}`
|
||||||
})
|
})
|
||||||
|
|
||||||
if (this.history !== null) {
|
if (this.history !== null) {
|
||||||
|
@ -21,7 +21,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
|
|
||||||
loader.start()
|
loader.start()
|
||||||
|
|
||||||
request.get(`http://${config.server_host}:${config.server_port}/v1/info`)
|
request.get(`${config.server_host}:${config.server_port}/v1/info`)
|
||||||
.end((err, res) => {
|
.end((err, res) => {
|
||||||
if (err || !res.ok) {
|
if (err || !res.ok) {
|
||||||
console.error(err.response.error.message)
|
console.error(err.response.error.message)
|
||||||
|
@ -10,9 +10,9 @@ const record = require('node-record-lpcm16')
|
|||||||
const { Detector, Models } = require('snowboy')
|
const { Detector, Models } = require('snowboy')
|
||||||
const io = require('socket.io-client')
|
const io = require('socket.io-client')
|
||||||
|
|
||||||
process.env.LEON_SERVER_HOST = process.env.LEON_SERVER_HOST || 'localhost'
|
process.env.LEON_SERVER_HOST = process.env.LEON_SERVER_HOST || 'http://localhost'
|
||||||
process.env.LEON_SERVER_PORT = process.env.LEON_SERVER_PORT || 1337
|
process.env.LEON_SERVER_PORT = process.env.LEON_SERVER_PORT || 1337
|
||||||
const url = `http://${process.env.LEON_SERVER_HOST}:${process.env.LEON_SERVER_PORT}`
|
const url = `${process.env.LEON_SERVER_HOST}:${process.env.LEON_SERVER_PORT}`
|
||||||
const socket = io(url)
|
const socket = io(url)
|
||||||
|
|
||||||
socket.on('connect', () => {
|
socket.on('connect', () => {
|
||||||
|
@ -32,7 +32,7 @@ export default () => new Promise((resolve) => {
|
|||||||
|
|
||||||
bs.init({
|
bs.init({
|
||||||
host: devip(),
|
host: devip(),
|
||||||
port: process.env.LEON_WEBAPP_PORT,
|
port: 4242,
|
||||||
open: true,
|
open: true,
|
||||||
server: {
|
server: {
|
||||||
baseDir: 'app/',
|
baseDir: 'app/',
|
||||||
|
@ -5,7 +5,11 @@
|
|||||||
*/
|
*/
|
||||||
const corsMidd = (req, res, next) => {
|
const corsMidd = (req, res, next) => {
|
||||||
// Allow only a specific client to request to the API (depending of the env)
|
// Allow only a specific client to request to the API (depending of the env)
|
||||||
res.header('Access-Control-Allow-Origin', `http://${process.env.LEON_WEBAPP_HOST}:${process.env.LEON_WEBAPP_PORT}`)
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
res.header('Access-Control-Allow-Origin', `${process.env.LEON_WEBAPP_HOST}:${process.env.LEON_WEBAPP_PORT}`)
|
||||||
|
} else {
|
||||||
|
res.header('Access-Control-Allow-Origin', `${process.env.LEON_WEBAPP_HOST}:4242`)
|
||||||
|
}
|
||||||
|
|
||||||
// Allow several headers for our requests
|
// Allow several headers for our requests
|
||||||
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
|
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
|
||||||
|
Loading…
Reference in New Issue
Block a user