18 lines
1.2 KiB
JavaScript
18 lines
1.2 KiB
JavaScript
|
|
import path from 'node:path';
|
||
|
|
import os from 'node:os';
|
||
|
|
import {fileURLToPath} from 'node:url';
|
||
|
|
import {createRequire} from 'node:module';
|
||
|
|
import {createOtaServer} from './ota-server.mjs';
|
||
|
|
const require=createRequire(import.meta.url);
|
||
|
|
const {internal}=require('../config/environment.cjs');
|
||
|
|
const development=require('../config/development.json');
|
||
|
|
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'../..');
|
||
|
|
const origin=new URL(internal(development.updateOrigin,false));
|
||
|
|
if(origin.protocol!=='http:'||origin.pathname!=='/')throw Error('Development listener requires a direct local HTTP origin');
|
||
|
|
const addresses=Object.values(os.networkInterfaces()).flat().filter(Boolean).map(item=>item.address);
|
||
|
|
if(!addresses.includes(origin.hostname))throw Error('Development update IP is not assigned to this computer; check config/development.json');
|
||
|
|
const server=createOtaServer({root:path.join(root,'.codex-tmp/app-dev-ota/data'),environments:['dev'],
|
||
|
|
downloadDirectory:path.join(root,'.codex-tmp/app-dev-ota/downloads')});
|
||
|
|
server.listen(Number(origin.port||80),origin.hostname,()=>console.log(`Development-only updates ready: ${origin.origin}/updates/dev`));
|
||
|
|
server.on('error',error=>{console.error(error.message);process.exitCode=1;});
|