-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
45 lines (37 loc) · 1.23 KB
/
Copy pathserver.js
File metadata and controls
45 lines (37 loc) · 1.23 KB
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
43
44
45
import express from 'express';
import Queue from 'queue';
import path from 'path';
import { fileURLToPath } from 'url';
import { randomUUID } from 'crypto';
import { Box } from './dist/backend/primitives.js';
const app = express();
app.use(express.json());
console.log("express.json middleware is set up.");
const q = new Queue({
concurrency: 1,
autostart: true
});
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
app.use(express.static(path.join(__dirname, 'src')));
app.get("/", (req, res) => {
res.sendFile(path.join(__dirname, 'src', 'index.html'));
});
app.use('/dist', express.static(path.join(__dirname, 'dist')));
app.post("/createBoxPrimitive", (req, res) => {
const { box_wid, box_hgt, box_dep, box_cnt } = req.body;
const box = new Box(box_wid, box_dep, box_hgt, box_cnt);
const box_uuid = randomUUID();
console.log("Creating and returning a box primitive...");
res.json({
id: box_uuid,
mesh: box.getBoxMesh()
});
});
app.post("/increaseBoxHeight", (req, res) => {
const { box_wid, box_hgt, box_dep, box_cnt } = req.body;
res.send("OK!");
});
app.listen(3000, () => {
console.log("App is running on http://localhost:3000...")
});