Add dev root routing

This commit is contained in:
Ben Allfree
2023-12-27 08:29:13 -08:00
parent 55b42b6f1d
commit 123e5dfe8d
3 changed files with 44 additions and 20 deletions

View File

@@ -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')
})
}