Fix bun test-server
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Siklos 2022-08-05 12:06:15 +02:00
parent cf1a3a7eec
commit 8fdf75019f

View file

@ -3,22 +3,31 @@ import { serve } from 'bun';
serve({ serve({
port: 5000, port: 5000,
fetch(request) { async fetch(request) {
console.log(`${request.method}: ${request.url}`); console.log(`${request.method}: ${request.url}`);
if (request.method === 'POST') { if (request.method === 'POST') {
const url = new URL(request.url); const url = new URL(request.url);
let json; let json;
if (url.pathname === '/GetSVGLayoutConfiguration') { if (url.pathname === '/GetSVGLayoutConfiguration') {
json = JSON.stringify(GetSVGLayoutConfiguration()); json = GetSVGLayoutConfiguration();
} else if (url.pathname === '/FillHoleWithChassis') { } else if (url.pathname === '/ApplicationState') {
json = JSON.stringify(FillHoleWithChassis(request)); const bodyParsed = await request.json();
} else if (url.pathname === '/SplitRemplissage') { console.log(bodyParsed);
json = JSON.stringify(SplitRemplissage(request)); switch (bodyParsed.Action) {
case 'FillHoleWithChassis':
json = FillHoleWithChassis(bodyParsed);
break;
case 'SplitRemplissage':
json = SplitRemplissage(bodyParsed);
break;
default:
break;
}
} else { } else {
// TODO: Return 404 rather than this // TODO: Return 404 rather than this
json = JSON.stringify(GetSVGLayoutConfiguration()); json = GetSVGLayoutConfiguration();
} }
return new Response(json, { return new Response(JSON.stringify(json), {
status: 200, status: 200,
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -108,18 +117,18 @@ const GetSVGLayoutConfiguration = () => {
const FillHoleWithChassis = (request) => { const FillHoleWithChassis = (request) => {
const maxWidthChassis = 3000; const maxWidthChassis = 3000;
const nbChassis = Math.ceil(request.ContainerActions.Width / maxWidthChassis); const nbChassis = Math.ceil(request.ContainerAction.Width / maxWidthChassis);
const lstModels = []; const lstModels = [];
for (let i = 0; i <= nbChassis; i++) { for (let i = 0; i <= nbChassis; i++) {
if (i === 1 && request.ContainerAction.ExistOnBefore) { if (i === 1 && request.ContainerAction.ExistOnBefore) {
lstModels.Add({ Type: 'Dilatation' }); lstModels.push({ Type: 'Dilatation' });
} }
lstModels.Add({ Type: 'Chassis' }); lstModels.push({ Type: 'Chassis' });
if (i < nbChassis) { if (i < nbChassis) {
lstModels.Add({ Type: 'Dilatation' }); lstModels.push({ Type: 'Dilatation' });
} }
if (i === nbChassis && request.ContainerAction.ExistOnAfter) { if (i === nbChassis && request.ContainerAction.ExistOnAfter) {
lstModels.Add({ Type: 'Dilatation' }); lstModels.push({ Type: 'Dilatation' });
} }
} }
return { return {