Fix node-http.js
This commit is contained in:
parent
d1e04769bb
commit
35bb95f206
1 changed files with 28 additions and 16 deletions
|
@ -2,27 +2,39 @@ import http from 'http';
|
|||
const host = 'localhost';
|
||||
const port = 5000;
|
||||
|
||||
const requestListener = function(request, response) {
|
||||
const requestListener = async(request, response) => {
|
||||
response.setHeader('Access-Control-Allow-Origin', '*');
|
||||
response.setHeader('Access-Control-Allow-Headers', '*');
|
||||
response.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
|
||||
if (request.method === 'POST') {
|
||||
response.setHeader('Access-Control-Allow-Origin', '*');
|
||||
response.setHeader('Content-Type', 'application/json');
|
||||
const url = request.url;
|
||||
let json;
|
||||
if (url === '/GetSVGLayoutConfiguration') {
|
||||
json = GetSVGLayoutConfiguration();
|
||||
} else if (url === '/FillHoleWithChassis') {
|
||||
json = FillHoleWithChassis(request);
|
||||
} else if (url === '/SplitRemplissage') {
|
||||
json = SplitRemplissage(request);
|
||||
if (url === '/ApplicationState') {
|
||||
const buffers = [];
|
||||
for await (const chunk of request) {
|
||||
buffers.push(chunk);
|
||||
}
|
||||
const data = Buffer.concat(buffers).toString();
|
||||
const bodyParsed = JSON.parse(data);
|
||||
console.log(bodyParsed);
|
||||
switch (bodyParsed.Action) {
|
||||
case 'FillHoleWithChassis':
|
||||
json = FillHoleWithChassis(bodyParsed);
|
||||
break;
|
||||
case 'SplitRemplissage':
|
||||
json = SplitRemplissage(bodyParsed);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// TODO: Return 404 rather than this
|
||||
// TODO: Return 404 rather than this
|
||||
json = GetSVGLayoutConfiguration();
|
||||
}
|
||||
response.writeHead(200);
|
||||
return response.end(JSON.stringify(json));
|
||||
} else if (request.method === 'OPTIONS') {
|
||||
response.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
|
||||
response.setHeader('Access-Control-Allow-Headers', '*');
|
||||
response.writeHead(200);
|
||||
return response.end();
|
||||
}
|
||||
|
@ -269,18 +281,18 @@ const GetSVGLayoutConfiguration = () => {
|
|||
|
||||
const FillHoleWithChassis = (request) => {
|
||||
const maxWidthChassis = 3000;
|
||||
const nbChassis = Math.ceil(request.ContainerActions.Width / maxWidthChassis);
|
||||
const nbChassis = Math.ceil(request.ContainerAction.Width / maxWidthChassis);
|
||||
const lstModels = [];
|
||||
for (let i = 0; i <= nbChassis; i++) {
|
||||
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) {
|
||||
lstModels.Add({ Type: 'Dilatation' });
|
||||
lstModels.push({ Type: 'Dilatation' });
|
||||
}
|
||||
if (i === nbChassis && request.ContainerAction.ExistOnAfter) {
|
||||
lstModels.Add({ Type: 'Dilatation' });
|
||||
lstModels.push({ Type: 'Dilatation' });
|
||||
}
|
||||
}
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue