-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathserver.js
More file actions
34 lines (28 loc) · 842 Bytes
/
server.js
File metadata and controls
34 lines (28 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const path = require('path')
const express = require('express')
const axios = require('axios')
const app = express()
// API Key Check
const apiKey = process.env.HB_API_KEY
if (!apiKey || apiKey === "") {
console.error("API Key is not set, did you set the HB_API_KEY environment variable to your API key?")
}
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '/index.html'))
})
// Get a cloud computer object. If no object exists, create it.
let computer
app.get('/computer', async (req, res) => {
if (computer) {
res.send(computer)
return
}
const resp = await axios.post('https://engine.hyperbeam.com/v0/vm', {}, {
headers: { 'Authorization': `Bearer ${apiKey}` }
})
computer = resp.data
res.send(computer)
})
app.listen(8080, () => {
console.log('Server start at http://localhost:8080')
})