Skip to content

Commit

Permalink
removes dependency on github api call
Browse files Browse the repository at this point in the history
  • Loading branch information
motdotla committed Jun 15, 2024
1 parent 407c71c commit 9f92edb
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,26 @@ fs.readFile(installerScriptPath, 'utf8', (err, data) => {
installerScript = data
})

// Read the version file once at the start
let currentVersion = '0.44.3' // hardcode for added redundancy (in case read fails somehow)
fs.readFile(path.join(__dirname, 'VERSION'), 'utf8', (err, data) => {
if (err) {
console.error('Error reading VERSION file', err)
process.exit(1) // Exit if the script cannot be read
}
currentVersion = data
})

app.get('/', (req, res) => {
res.type('text/plain')
res.send(installerScript)
})

app.get('/VERSION', (req, res) => {
res.type('text/plain')
res.send(currentVersion)
})

app.get('/:os/:arch', async (req, res) => {
const os = req.params.os.toLowerCase()
let arch = req.params.arch.toLowerCase()
Expand Down Expand Up @@ -89,22 +104,6 @@ app.get('/:os/:arch', async (req, res) => {
}
})

app.get('/VERSION', async (req, res) => {
const proxyUrl = 'https://dotenvx.com/releases/VERSION'

try {
// Using axios to get the response as text
const response = await axios.get(proxyUrl, {
responseType: 'text' // Fetch as plain text
})

res.type('text/plain')
res.send(response.data)
} catch (error) {
res.status(500).send('Error occurred while fetching the data: ' + error.message)
}
})

app.get('/installer.sh', (req, res) => {
const scriptPath = path.join(__dirname, 'installer.sh')

Expand Down

0 comments on commit 9f92edb

Please sign in to comment.