WIP backend improvements

This commit is contained in:
Alan O'Cull 2023-12-05 16:48:02 -05:00
parent 193f495e00
commit 5646c84a89
3 changed files with 40 additions and 19 deletions

View File

@ -3,7 +3,7 @@
<head>
<title>Pattern Packer</title>
<link rel="stylesheet" href="../css/puzzle.css">
<link rel="stylesheet" href="css/puzzle.css">
<script src="client.js"></script>
</head>
<body>

View File

@ -1,13 +1,36 @@
import { Mesh, MeshImport } from "./mesh";
const request_mesh_handler = (e: ProgressEvent<XMLHttpRequestEventTarget>) => {
console.log(`XML REQUEST ${e.type}: ${e.loaded} bytes transferred\n`);
}
const request_mesh_listeners = (xhr: XMLHttpRequest) => {
xhr.addEventListener("loadstart", request_mesh_handler);
xhr.addEventListener("load", request_mesh_handler);
xhr.addEventListener("loadend", request_mesh_handler);
xhr.addEventListener("progress", request_mesh_handler);
xhr.addEventListener("error", request_mesh_handler);
xhr.addEventListener("abort", request_mesh_handler);
}
const request_mesh = (filename: string) => {
let request = new XMLHttpRequest();
request.open('GET', `http://localho.st:${3000}/mesh/${filename}`, false);
request_mesh_listeners(request);
request.onreadystatechange = function() {
if (request.readyState == XMLHttpRequest.DONE) {
alert(request.responseText);
const mesh = MeshImport.parse(request.responseText);
console.log(`Got mesh array at ${mesh.name}`);
console.log(mesh.shells);
}
}
request.open('GET', `http://localhost:${3000}/mesh/${filename}`, true);
request.send(null);
return request.responseText;
return request;
}
const buff = request_mesh('clover.obj');
const mesh = MeshImport.parse(buff);
console.log(`Got mesh array at ${mesh.name}`);
console.log(mesh.shells);
document.onload = function() {
console.log('PAGE LOADED');
const req = request_mesh('clover.obj');
}

View File

@ -8,19 +8,17 @@ dotenv.config();
const app: Express = express();
const port = process.env.PORT;
app.get('/', (req: Request, res: Response) => {
console.log(req.url);
console.log(req.body);
console.log(req.query);
const last = req.url.lastIndexOf('/');
const mesh_name = req.url.substring(last + 1);
const filepath = `assets/pages/${mesh_name}`;
app.get('/mesh/*', (req: Request, res: Response) => {
console.log('Got MESH request ', req.url);
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
app.use(express.static('dist/public/objects/hard'));
});
if (fs.existsSync(filepath)) {
fs.readFileSync(`assets/pages/${mesh_name}`).toString('utf8');
} else {
res.send('o hello world');
}
app.get('/', (req: Request, res: Response) => {
console.log('Got MAIN request ', req.url);
app.use(express.static('dist' + '/public'));
});
app.listen(port, () => {