|
|
|
@ -22,42 +22,6 @@ await fastify.register(cors, {
|
|
|
|
|
origin: process.env.ALLOW_ORIGIN || "*",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/* Code runner in a container */
|
|
|
|
|
|
|
|
|
|
/* POST /run : Run code in a container */
|
|
|
|
|
|
|
|
|
|
fastify.post(
|
|
|
|
|
"/run",
|
|
|
|
|
{
|
|
|
|
|
schema: {
|
|
|
|
|
body: Type.Object({
|
|
|
|
|
code: Type.String(),
|
|
|
|
|
language: Type.String(),
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
(req, reply) => {
|
|
|
|
|
const { code, language } = req.body;
|
|
|
|
|
const jobId = generateId();
|
|
|
|
|
const buffer = allocateBuffer(jobId, code, IMAGES.moshell);
|
|
|
|
|
reply.raw.writeHead(200, {
|
|
|
|
|
"Content-Type": "text/event-stream",
|
|
|
|
|
Connection: "keep-alive",
|
|
|
|
|
"Cache-Control": "no-cache",
|
|
|
|
|
"Access-Control-Allow-Origin": process.env.ALLOW_ORIGIN || "*",
|
|
|
|
|
});
|
|
|
|
|
reply.raw.on("close", () => {
|
|
|
|
|
delete clients[jobId];
|
|
|
|
|
});
|
|
|
|
|
sender.send(buffer).then(() => {
|
|
|
|
|
reply.raw.write("event: connected\n");
|
|
|
|
|
reply.raw.write(`data: ${jobId}\n`);
|
|
|
|
|
reply.raw.write("id: 0\n\n");
|
|
|
|
|
});
|
|
|
|
|
clients[jobId] = reply;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/* Database */
|
|
|
|
|
|
|
|
|
|
/* Création du répertoire de la base de données s'il n'existe pas */
|
|
|
|
|