Enable remote launcher catalog source
This commit is contained in:
@@ -14,6 +14,7 @@ const LAUNCHER_CATALOG_PATH = path.join(PROJECT_ROOT, 'app', 'assets', 'launcher
|
||||
const PUBLIC_DIR = path.join(__dirname, 'public')
|
||||
const SAMPLE_DISTRIBUTION_PATH = path.join(PROJECT_ROOT, 'docs', 'sample_distribution.json')
|
||||
const EXAMPLE_DISTRIBUTION_PREFIX = 'https://example.com/launcher/'
|
||||
const PUBLIC_BASE_URL = normalizeText(process.env.LAUNCHER_PUBLIC_BASE_URL).replace(/\/+$/, '')
|
||||
|
||||
function normalizeText(value){
|
||||
return typeof value === 'string' ? value.trim() : ''
|
||||
@@ -45,6 +46,13 @@ function normalizeBoolean(value){
|
||||
return value === true
|
||||
}
|
||||
|
||||
function getPublicBaseUrl(){
|
||||
if(PUBLIC_BASE_URL.length > 0){
|
||||
return PUBLIC_BASE_URL
|
||||
}
|
||||
return `http://${HOST}:${PORT}`
|
||||
}
|
||||
|
||||
function resolveSafeProjectPath(relativePath){
|
||||
const resolvedPath = path.resolve(PROJECT_ROOT, relativePath)
|
||||
if(!resolvedPath.startsWith(PROJECT_ROOT + path.sep) && resolvedPath !== PROJECT_ROOT){
|
||||
@@ -259,6 +267,7 @@ async function start(){
|
||||
|
||||
app.use(express.json({ limit: '5mb' }))
|
||||
app.use('/uploads', express.static(UPLOADS_DIR))
|
||||
app.use('/admin/data/uploads', express.static(UPLOADS_DIR))
|
||||
app.use('/admin/data/distributions', express.static(DISTRIBUTIONS_DIR))
|
||||
|
||||
app.get('/api/meta', async (_req, res) => {
|
||||
@@ -267,7 +276,7 @@ async function start(){
|
||||
port: PORT,
|
||||
runtimeCatalogPath: toProjectRelativePath(RUNTIME_CATALOG_PATH),
|
||||
launcherCatalogPath: toProjectRelativePath(LAUNCHER_CATALOG_PATH),
|
||||
localCatalogUrl: `http://${HOST}:${PORT}/catalog.json`,
|
||||
localCatalogUrl: `${getPublicBaseUrl()}/catalog.json`,
|
||||
distributionsPath: toProjectRelativePath(DISTRIBUTIONS_DIR)
|
||||
})
|
||||
})
|
||||
@@ -362,7 +371,7 @@ async function start(){
|
||||
storedName: req.file.filename,
|
||||
size: req.file.size,
|
||||
path: relativePath,
|
||||
localUrl: `http://${HOST}:${PORT}/uploads/${encodeURIComponent(req.file.filename)}`
|
||||
localUrl: `${getPublicBaseUrl()}/uploads/${encodeURIComponent(req.file.filename)}`
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
@@ -394,7 +403,7 @@ async function start(){
|
||||
ok: true,
|
||||
file: {
|
||||
path: relativePath,
|
||||
localUrl: `http://${HOST}:${PORT}/${relativePath}`
|
||||
localUrl: `${getPublicBaseUrl()}/${relativePath}`
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user