|
|
@ -2,7 +2,7 @@ import cors from '@fastify/cors';
|
|
|
|
import { Type, TypeBoxTypeProvider } from '@fastify/type-provider-typebox';
|
|
|
|
import { Type, TypeBoxTypeProvider } from '@fastify/type-provider-typebox';
|
|
|
|
import Fastify, { FastifyReply } from 'fastify';
|
|
|
|
import Fastify, { FastifyReply } from 'fastify';
|
|
|
|
import { nanoid } from 'nanoid';
|
|
|
|
import { nanoid } from 'nanoid';
|
|
|
|
import { allocateBuffer, IMAGES } from 'runner';
|
|
|
|
import { allocateBuffer, getRunner } from 'runner';
|
|
|
|
import { Pull, Push } from 'zeromq';
|
|
|
|
import { Pull, Push } from 'zeromq';
|
|
|
|
|
|
|
|
|
|
|
|
const sender = new Push();
|
|
|
|
const sender = new Push();
|
|
|
@ -29,8 +29,12 @@ fastify.post('/run', {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, (req, reply) => {
|
|
|
|
}, (req, reply) => {
|
|
|
|
const { code, language } = req.body;
|
|
|
|
const { code, language } = req.body;
|
|
|
|
|
|
|
|
const runner = getRunner(language);
|
|
|
|
|
|
|
|
if (runner === null) {
|
|
|
|
|
|
|
|
return reply.status(422).send({ error: 'Invalid language' });
|
|
|
|
|
|
|
|
}
|
|
|
|
const jobId = generateId();
|
|
|
|
const jobId = generateId();
|
|
|
|
const buffer = allocateBuffer(jobId, code, IMAGES.moshell);
|
|
|
|
const buffer = allocateBuffer(jobId, code, runner);
|
|
|
|
reply.raw.writeHead(200, {
|
|
|
|
reply.raw.writeHead(200, {
|
|
|
|
'Content-Type': 'text/event-stream',
|
|
|
|
'Content-Type': 'text/event-stream',
|
|
|
|
Connection: 'keep-alive',
|
|
|
|
Connection: 'keep-alive',
|
|
|
|