mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 02:24:16 +00:00
Improve SSL mode
This commit is contained in:
parent
668fa12a87
commit
73bce287db
@ -6,9 +6,7 @@ import aliases from "./aliases"
|
|||||||
import { defineConfig } from "vite"
|
import { defineConfig } from "vite"
|
||||||
import react from "@vitejs/plugin-react"
|
import react from "@vitejs/plugin-react"
|
||||||
|
|
||||||
const backendUri = "https://0.0.0.0:9000"
|
const sslDirPath = path.resolve(__dirname, "../../", ".ssl")
|
||||||
const oneYearInSeconds = 60 * 60 * 24 * 365
|
|
||||||
const sslDirPath = path.join(__dirname, ".ssl")
|
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
@ -22,11 +20,11 @@ const config = {
|
|||||||
allow: ["..", "../../"],
|
allow: ["..", "../../"],
|
||||||
},
|
},
|
||||||
headers: {
|
headers: {
|
||||||
"Strict-Transport-Security": `max-age=${oneYearInSeconds}`,
|
"Strict-Transport-Security": `max-age=31536000`,
|
||||||
},
|
},
|
||||||
proxy: {
|
proxy: {
|
||||||
"/api": {
|
"/api": {
|
||||||
target: backendUri,
|
target: "http://0.0.0.0:9000",
|
||||||
rewrite: (path) => path.replace(/^\/api/, ""),
|
rewrite: (path) => path.replace(/^\/api/, ""),
|
||||||
hostRewrite: true,
|
hostRewrite: true,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
@ -50,11 +48,23 @@ const config = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (fs.existsSync(sslDirPath)) {
|
if (fs.existsSync(sslDirPath)) {
|
||||||
// config.server.https = {
|
const keyPath = path.join(sslDirPath, "privkey.pem")
|
||||||
// key: path.join(__dirname, ".ssl", "privkey.pem"),
|
const certPath = path.join(sslDirPath, "cert.pem")
|
||||||
// cert: path.join(__dirname, ".ssl", "cert.pem"),
|
|
||||||
// }
|
if (fs.existsSync(keyPath) && fs.existsSync(certPath)) {
|
||||||
// }
|
console.info(`Starting server on SSL mode > [${sslDirPath}]`)
|
||||||
|
|
||||||
|
config.server.proxy["/api"].target = "https://0.0.0.0:9000"
|
||||||
|
config.server.https = {
|
||||||
|
key: keyPath,
|
||||||
|
cert: certPath,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error(
|
||||||
|
`SSL path finded, but some files are missing. Disabling ssl mode.\nRequired files:\n\t${keyPath}\n\t${certPath}`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default defineConfig(config)
|
export default defineConfig(config)
|
||||||
|
@ -20,15 +20,12 @@ import * as Managers from "./managers"
|
|||||||
global.debugFlag = process.env.DEBUG === "true"
|
global.debugFlag = process.env.DEBUG === "true"
|
||||||
const isProduction = process.env.NODE_ENV === "production"
|
const isProduction = process.env.NODE_ENV === "production"
|
||||||
|
|
||||||
const sslKey = path.resolve(process.cwd(), ".ssl", "privkey.pem")
|
|
||||||
const sslCert = path.resolve(process.cwd(), ".ssl", "cert.pem")
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gateway class - Main entry point for the service orchestrator
|
* Gateway class - Main entry point for the service orchestrator
|
||||||
* Manages service discovery, spawning, and communication
|
* Manages service discovery, spawning, and communication
|
||||||
*/
|
*/
|
||||||
export default class Gateway {
|
export default class Gateway {
|
||||||
static gatewayMode = process.env.GATEWAY_MODE ?? "http_proxy"
|
static gatewayMode = process.env.GATEWAY_MODE ?? "nginx"
|
||||||
|
|
||||||
eventBus = new EventEmitter()
|
eventBus = new EventEmitter()
|
||||||
|
|
||||||
@ -382,8 +379,8 @@ export default class Gateway {
|
|||||||
this.gateway = new Managers[this.constructor.gatewayMode]({
|
this.gateway = new Managers[this.constructor.gatewayMode]({
|
||||||
port: this.state.proxyPort,
|
port: this.state.proxyPort,
|
||||||
internalIp: this.state.internalIp,
|
internalIp: this.state.internalIp,
|
||||||
cert_file_name: sslCert,
|
key_file_name: process.env.GATEWAY_SSL_KEY,
|
||||||
key_file_name: sslKey,
|
cert_file_name: process.env.GATEWAY_SSL_CERT,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (typeof this.gateway.initialize === "function") {
|
if (typeof this.gateway.initialize === "function") {
|
||||||
|
@ -7,10 +7,6 @@ import defaults from "linebridge/dist/defaults"
|
|||||||
const localNginxBinary = path.resolve(process.cwd(), "nginx-bin")
|
const localNginxBinary = path.resolve(process.cwd(), "nginx-bin")
|
||||||
const serverPkg = require("../../../package.json")
|
const serverPkg = require("../../../package.json")
|
||||||
|
|
||||||
/**
|
|
||||||
* NginxManager - Optimized version that batches configurations
|
|
||||||
* Waits for all services to register before applying configuration
|
|
||||||
*/
|
|
||||||
export default class NginxManager {
|
export default class NginxManager {
|
||||||
constructor(options = {}) {
|
constructor(options = {}) {
|
||||||
this.options = options
|
this.options = options
|
||||||
|
@ -1,3 +1,24 @@
|
|||||||
|
import fs from "node:fs"
|
||||||
|
import path from "node:path"
|
||||||
|
|
||||||
import Gateway from "./gateway"
|
import Gateway from "./gateway"
|
||||||
|
|
||||||
new Gateway().initialize()
|
const rootSSLDirPath = path.resolve(__dirname, "../../", ".ssl")
|
||||||
|
const cwdSSLDirPath = path.resolve(__dirname, ".ssl")
|
||||||
|
|
||||||
|
if (fs.existsSync(rootSSLDirPath) || fs.existsSync(cwdSSLDirPath)) {
|
||||||
|
const rootKeyPath = path.resolve(rootSSLDirPath, "privkey.pem")
|
||||||
|
const rootCertPath = path.resolve(rootSSLDirPath, "cert.pem")
|
||||||
|
const cwdKeyPath = path.resolve(cwdSSLDirPath, "privkey.pem")
|
||||||
|
const cwdCertPath = path.resolve(cwdSSLDirPath, "cert.pem")
|
||||||
|
|
||||||
|
if (fs.existsSync(rootKeyPath) && fs.existsSync(rootCertPath)) {
|
||||||
|
process.env.GATEWAY_SSL_KEY = rootKeyPath
|
||||||
|
process.env.GATEWAY_SSL_CERT = rootCertPath
|
||||||
|
} else if (fs.existsSync(cwdKeyPath) && fs.existsSync(cwdCertPath)) {
|
||||||
|
process.env.GATEWAY_SSL_KEY = cwdKeyPath
|
||||||
|
process.env.GATEWAY_SSL_CERT = cwdCertPath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new Gateway().initialize()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user