-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
45 lines (35 loc) · 1.35 KB
/
server.js
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
35
36
37
38
39
40
41
42
const express = require('express');
const onshape = require("./lib/onshapeAPI");
const cors = require('cors');
const app = express();
const port = process.env.PORT || 5000;
if(process.env.NODE_ENV === 'production') {
app.use(cors());
} else {
app.use(cors({ origin: "http://localhost:3000" }));
}
app.get('/configparams', (req, res) => {
onshape.getConfigurationParams()
.then(reponse => res.send(reponse));
});
app.get('/retrievemodelstl/:paramstoupdate', (req, res) => {
let newConfigParameters = JSON.parse(req.params.paramstoupdate);
onshape.configureAndTranslateSTL(newConfigParameters)
.then(stlModelData => res.send(stlModelData))
.catch(error => console.log(error));
});
app.get('/retrievemodel/:paramstoupdate', (req, res) => {
let newConfigParameters = JSON.parse(req.params.paramstoupdate);
onshape.configureAndTranslate(newConfigParameters)
.then(gltfModelData => res.send(gltfModelData))
.catch(error => console.log(error));
});
app.get('/defaultmodel', (req, res) => {
onshape.fullTranslation()
.then(gltfModelData => res.send(gltfModelData))
.catch(error => { res.send(error); console.log(error); });
});
if(process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
}
app.listen(port, () => console.log(`Express server running on ${port}.`));