but also upgrade the cad lamdbas to use built javascript files, allowing us to use typescript, and patching redwood
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
const express = require('express')
|
|
var cors = require('cors')
|
|
const axios = require('axios')
|
|
const { restart } = require('nodemon')
|
|
const app = express()
|
|
const port = 8080
|
|
app.use(express.json())
|
|
app.use(cors())
|
|
|
|
const invocationURL = (port) =>
|
|
`http://localhost:${port}/2015-03-31/functions/function/invocations`
|
|
|
|
const makeRequest = (route, port) => [
|
|
route,
|
|
async (req, res) => {
|
|
console.log(`making post request to ${port}, ${route}`)
|
|
try {
|
|
const { data } = await axios.post(invocationURL(port), {
|
|
body: Buffer.from(JSON.stringify(req.body)).toString('base64'),
|
|
})
|
|
res.status(data.statusCode)
|
|
res.setHeader('Content-Type', 'application/javascript')
|
|
res.setHeader('Content-Encoding', 'gzip')
|
|
res.send(Buffer.from(data.body, 'base64'))
|
|
} catch (e) {
|
|
res.status(500)
|
|
res.send()
|
|
}
|
|
},
|
|
]
|
|
|
|
app.post(...makeRequest('/openscad/preview', 5052))
|
|
app.post(...makeRequest('/openscad/stl', 5053))
|
|
app.post(...makeRequest('/cadquery/stl', 5060))
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Example app listening at http://localhost:${port}`)
|
|
})
|