1
0
Fork 0
mirror of https://github.com/engineer-man/piston.git synced 2025-05-01 17:36:28 +02:00
This commit is contained in:
Thomas Hobson 2021-04-25 20:55:20 +12:00
parent 436c7f3c25
commit 3928bace86
No known key found for this signature in database
GPG key ID: 9F1FD9D87950DB6F
7 changed files with 224 additions and 230 deletions
api/src

View file

@ -9,7 +9,6 @@ const fs = require('fs/promises');
const fss = require('fs');
const body_parser = require('body-parser');
const runtime = require('./runtime');
const { validationResult } = require('express-validator');
const logger = Logger.create('index');
const app = express();
@ -67,48 +66,10 @@ const app = express();
})
})
const validate = (req, res, next) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res
.status(400)
.send({
message: errors.array()
});
}
next();
};
logger.debug('Registering Routes');
const ppman_routes = require('./ppman/routes');
const executor_routes = require('./executor/routes');
app.get('/api/v1/packages', ppman_routes.package_list);
app.post('/api/v1/packages/:language/:version', ppman_routes.package_install);
app.delete('/api/v1/packages/:language/:version', ppman_routes.package_uninstall);
app.post('/api/v1/execute',
executor_routes.run_job_validators,
validate,
executor_routes.run_job
);
app.get('/api/v1/runtimes', (req, res) => {
const runtimes = runtime
.map(rt => {
return {
language: rt.language,
version: rt.version.raw,
aliases: rt.aliases,
runtime: rt.runtime
};
});
return res
.status(200)
.send(runtimes);
});
const api_v1 = require('./api/v1')
app.use('/api/v1', api_v1);
app.use(function (req,res,next){
return res.status(404).send({message: 'Not Found'});