mirror of
https://github.com/pockethost/pockethost.git
synced 2026-03-19 14:48:54 +00:00
Add dev root routing
This commit is contained in:
@@ -2,6 +2,7 @@ import {
|
||||
DAEMON_PORT,
|
||||
DefaultSettingsService,
|
||||
IPCIDR_LIST,
|
||||
IS_DEV,
|
||||
MOTHERSHIP_PORT,
|
||||
SETTINGS,
|
||||
} from '$constants'
|
||||
@@ -9,6 +10,7 @@ import { forEach } from '@s-libs/micro-dash'
|
||||
import cors from 'cors'
|
||||
import express from 'express'
|
||||
import fs from 'fs'
|
||||
import http from 'http'
|
||||
import https from 'https'
|
||||
|
||||
import { createIpWhitelistMiddleware } from './cidr'
|
||||
@@ -16,10 +18,19 @@ import { createVhostProxyMiddleware } from './createVhostProxyMiddleware'
|
||||
|
||||
DefaultSettingsService(SETTINGS)
|
||||
|
||||
const hostnameRoutes = {
|
||||
const PROD_ROUTES = {
|
||||
'pockethost-central.pockethost.io': `http://localhost:${MOTHERSHIP_PORT()}`,
|
||||
'*.pockethost.io': `http://localhost:${DAEMON_PORT()}`,
|
||||
}
|
||||
const DEV_ROUTES = {
|
||||
'mail.pockethost.lvh.me': `http://localhost:${1080}`,
|
||||
'pockethost-central.pockethost.lvh.me': `http://localhost:${MOTHERSHIP_PORT()}`,
|
||||
'app.pockethost.lvh.me': `http://localhost:${5174}`,
|
||||
'superadmin.pockethost.lvh.me': `http://localhost:${5175}`,
|
||||
'pockethost.lvh.me': `http://localhost:${8080}`,
|
||||
'*.pockethost.lvh.me': `http://localhost:${DAEMON_PORT()}`,
|
||||
}
|
||||
const hostnameRoutes = IS_DEV() ? DEV_ROUTES : PROD_ROUTES
|
||||
|
||||
// Create Express app
|
||||
const app = express()
|
||||
@@ -33,17 +44,23 @@ forEach(hostnameRoutes, (target, host) => {
|
||||
app.use(createVhostProxyMiddleware(host, target))
|
||||
})
|
||||
|
||||
// HTTPS server options
|
||||
const httpsOptions = {
|
||||
key: fs.readFileSync(
|
||||
'/home/pockethost/pockethost/ssl/cloudflare-privkey.pem',
|
||||
),
|
||||
cert: fs.readFileSync(
|
||||
'/home/pockethost/pockethost/ssl/cloudflare-origin.pem',
|
||||
),
|
||||
}
|
||||
if (IS_DEV()) {
|
||||
http.createServer(app).listen(80, () => {
|
||||
console.log('HTTP server running on port 80')
|
||||
})
|
||||
} else {
|
||||
// HTTPS server options
|
||||
const httpsOptions = {
|
||||
key: fs.readFileSync(
|
||||
'/home/pockethost/pockethost/ssl/cloudflare-privkey.pem',
|
||||
),
|
||||
cert: fs.readFileSync(
|
||||
'/home/pockethost/pockethost/ssl/cloudflare-origin.pem',
|
||||
),
|
||||
}
|
||||
|
||||
// Create HTTPS server
|
||||
https.createServer(httpsOptions, app).listen(443, () => {
|
||||
console.log('HTTPS server running on port 443')
|
||||
})
|
||||
// Create HTTPS server
|
||||
https.createServer(httpsOptions, app).listen(443, () => {
|
||||
console.log('HTTPS server running on port 443')
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user