From e86c19b0070ce2971a42fab9c300461769ede4c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Barbi=C4=87?= Date: Wed, 11 Jan 2023 18:59:29 +0100 Subject: [PATCH] return 200 and piston ver on /, fix empty content-type header validation --- api/package.json | 2 +- api/src/api/v2.js | 2 +- api/src/index.js | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/api/package.json b/api/package.json index 366ce9f..0b91c01 100644 --- a/api/package.json +++ b/api/package.json @@ -1,6 +1,6 @@ { "name": "piston-api", - "version": "3.1.0", + "version": "3.1.1", "description": "API for piston - a high performance code execution engine", "main": "src/index.js", "dependencies": { diff --git a/api/src/api/v2.js b/api/src/api/v2.js index 4f0c3e2..38b7c85 100644 --- a/api/src/api/v2.js +++ b/api/src/api/v2.js @@ -163,7 +163,7 @@ router.use((req, res, next) => { return next(); } - if (!req.headers['content-type'].startsWith('application/json')) { + if (!req.headers['content-type']?.startsWith('application/json')) { return res.status(415).send({ message: 'requests must be of type application/json', }); diff --git a/api/src/index.js b/api/src/index.js index 2870902..8a21e57 100644 --- a/api/src/index.js +++ b/api/src/index.js @@ -79,6 +79,12 @@ expressWs(app); const api_v2 = require('./api/v2'); app.use('/api/v2', api_v2); + const { version } = require('../package.json'); + + app.get('/', (req, res, next) => { + return res.status(200).send({ message: `Piston v${version}` }); + }); + app.use((req, res, next) => { return res.status(404).send({ message: 'Not Found' }); });