set up local development for openscad lamdas
and make a start on combining with Three.js IdeViewer Resolves #227 related #231
This commit is contained in:
34
api/src/docker/aws-emulator.js
Normal file
34
api/src/docker/aws-emulator.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const express = require('express')
|
||||
var cors = require('cors')
|
||||
const axios = require('axios')
|
||||
const stream = require('stream')
|
||||
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`
|
||||
|
||||
app.post('/render', async (req, res) => {
|
||||
const { data } = await axios.post(invocationURL(5052), {
|
||||
body: Buffer.from(JSON.stringify(req.body)).toString('base64'),
|
||||
})
|
||||
if (data.statusCode !== 200) {
|
||||
res.status(data.statusCode)
|
||||
res.send(res.body)
|
||||
} else {
|
||||
const fileContents = Buffer.from(data.body, 'base64')
|
||||
|
||||
const readStream = new stream.PassThrough()
|
||||
readStream.end(fileContents)
|
||||
|
||||
res.set('Content-disposition', 'attachment; filename=' + 'output')
|
||||
res.set('Content-Type', 'image/png')
|
||||
readStream.pipe(res)
|
||||
}
|
||||
})
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Example app listening at http://localhost:${port}`)
|
||||
})
|
||||
Reference in New Issue
Block a user