Spaces:
Paused
Paused
| const { exec } = require('child_process'); | |
| const fs = require('fs').promises; | |
| const path = require('path'); | |
| const zipUrl = process.env.ZIP_URL; | |
| const downloadPath = '/tmp/app.zip'; | |
| const extractPath = '/app'; | |
| async function runCommand(command) { | |
| return new Promise((resolve, reject) => { | |
| exec(command, (error, stdout, stderr) => { | |
| if (error) { | |
| console.error(`Error executing command: ${command}`); | |
| console.error(stderr); | |
| reject(error); | |
| return; | |
| } | |
| console.log(`Command executed successfully: ${command}`); | |
| console.log(stdout); | |
| resolve(stdout); | |
| }); | |
| }); | |
| } | |
| async function main() { | |
| if (!zipUrl) { | |
| console.error("Error: ZIP_URL environment variable not set."); | |
| process.exit(1); | |
| } | |
| try { | |
| console.log(`Downloading ZIP file from: ${zipUrl} to ${downloadPath}`); | |
| await runCommand(`wget "${zipUrl}" -O ${downloadPath}`); | |
| console.log(`Extracting ZIP file to: ${extractPath}`); | |
| await runCommand(`unzip -o ${downloadPath} -d ${extractPath}`); | |
| console.log("Removing downloaded ZIP file..."); | |
| await fs.unlink(downloadPath); | |
| console.log("Starting the application..."); | |
| await runCommand('npm start'); | |
| } catch (error) { | |
| console.error("An error occurred:", error); | |
| process.exit(1); | |
| } | |
| } | |
| main(); |