7 Commits

Author SHA1 Message Date
Maximilian Baum
5be3d127bb more math routes
All checks were successful
Build and Deploy / build (push) Successful in 21s
Build and Deploy / deploy (push) Successful in 25s
Build Release / build (push) Successful in 19s
2026-04-02 14:03:56 +02:00
Maximilian Baum
aacb2f4287 bugfix
All checks were successful
Build and Deploy / build (push) Successful in 19s
Build and Deploy / deploy (push) Successful in 24s
Build Release / build (push) Successful in 19s
2026-04-02 11:38:37 +02:00
Maximilian Baum
d1edd55b36 added add route
All checks were successful
Build and Deploy / build (push) Successful in 20s
Build and Deploy / deploy (push) Successful in 24s
2026-04-02 11:36:58 +02:00
Maximilian Baum
093bdd3625 release action
All checks were successful
Build and Deploy / build (push) Successful in 20s
Build and Deploy / deploy (push) Successful in 25s
Build Release / build (push) Successful in 18s
2026-04-02 10:50:29 +02:00
Maximilian Baum
c0f81934be node upgrade
All checks were successful
Build and Deploy / build (push) Successful in 43s
Build and Deploy / deploy (push) Successful in 25s
2026-04-02 10:44:30 +02:00
Maximilian Baum
1924b1d262 doc update
All checks were successful
Build and Deploy / build (push) Successful in 20s
Build and Deploy / deploy (push) Successful in 25s
2026-04-02 10:06:02 +02:00
Maximilian Baum
9228ebbe5b added stalin sort
All checks were successful
Build and Deploy / build (push) Successful in 21s
Build and Deploy / deploy (push) Successful in 26s
2026-04-02 09:55:20 +02:00
11 changed files with 439 additions and 27 deletions

View File

@@ -0,0 +1,28 @@
name: Build Release
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to Gitea Registry
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | \
docker login https://gitea.johannesbot.de -u ${{ secrets.REGISTRY_USER }} --password-stdin
- name: Extract Tag
id: tag
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT"
- name: Build Image
run: docker build -t gitea.johannesbot.de/johannesbot/stupid-apis:${{ steps.tag.outputs.VERSION }} .
- name: Push Image
run: docker push gitea.johannesbot.de/johannesbot/stupid-apis:${{ steps.tag.outputs.VERSION }}

View File

@@ -1,5 +1,5 @@
# Basis-Image # Basis-Image
FROM node:20 FROM node:24.14
# Arbeitsverzeichnis # Arbeitsverzeichnis
WORKDIR /app WORKDIR /app

View File

@@ -1,23 +0,0 @@
events {}
http {
upstream stupid_apis {
server stupid-apis-1:3000;
server stupid-apis-2:3000;
server stupid-apis-3:3000;
}
server {
listen 80;
location / {
proxy_pass http://stupid_apis;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
}

14
src/routes/api/add.js Normal file
View File

@@ -0,0 +1,14 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
res.json({ ret: input.a + input.b });
});
router.get('/:a/:b', (req, res) => {
res.json({ ret: Number(req.params.a) + Number(req.params.b) });
});
module.exports = router;

14
src/routes/api/divide.js Normal file
View File

@@ -0,0 +1,14 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
res.json({ ret: input.a / input.b });
});
router.get('/:a/:b', (req, res) => {
res.json({ ret: Number(req.params.a) / Number(req.params.b) });
});
module.exports = router;

View File

@@ -0,0 +1,14 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
res.json({ ret: input.a * input.b });
});
router.get('/:a/:b', (req, res) => {
res.json({ ret: Number(req.params.a) * Number(req.params.b) });
});
module.exports = router;

View File

@@ -15,7 +15,7 @@ router.post('/', (req, res) => {
return String(a).localeCompare(String(b)); return String(a).localeCompare(String(b));
}); });
res.json({ sortedArray }); res.json({ ret: sortedArray });
}); });
module.exports = router; module.exports = router;

View File

@@ -0,0 +1,29 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
if (!Array.isArray(input)) {
return res.status(400).json({ error: 'Request body muss ein Feld "array" mit einem Array enthalten' });
}
const sortedArray = Array();
sortedArray.push(input[0]);
let executions = 0;
for (let i = 1; i < input.length; i++) {
if (input[i] > input[i - 1]) {
sortedArray.push(input[i]);
} else {
executions++;
}
}
res.json({
ret: sortedArray,
executions
});
});
module.exports = router;

View File

@@ -0,0 +1,14 @@
const express = require('express');
const router = express.Router();
router.post('/', (req, res) => {
const { input } = req.body;
res.json({ ret: input.a - input.b });
});
router.get('/:a/:b', (req, res) => {
res.json({ ret: Number(req.params.a) - Number(req.params.b) });
});
module.exports = router;

View File

@@ -6,6 +6,10 @@
"description": "API Documentation for Stupid APIs" "description": "API Documentation for Stupid APIs"
}, },
"servers": [ "servers": [
{
"url": "/api",
"description": "Current host server"
},
{ {
"url": "http://localhost:3000/api", "url": "http://localhost:3000/api",
"description": "Local server" "description": "Local server"
@@ -24,7 +28,8 @@
"properties": { "properties": {
"input": { "input": {
"type": "array", "type": "array",
"items": {} "items": {},
"example": [3, 1, 4, 1, 5, 9]
} }
} }
} }
@@ -39,7 +44,7 @@
"schema": { "schema": {
"type": "object", "type": "object",
"properties": { "properties": {
"sortedArray": { "ret": {
"type": "array", "type": "array",
"items": {} "items": {}
} }
@@ -51,6 +56,49 @@
} }
} }
}, },
"/stalinSort": {
"post": {
"summary": "Sorts an array using Stalin Sort",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "array",
"items": {},
"example": [3, 1, 4, 1, 5, 9]
}
}
}
}
}
},
"responses": {
"200": {
"description": "Sorted array and execution count",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"ret": {
"type": "array",
"items": {}
},
"executions": {
"type": "number"
}
}
}
}
}
}
}
}
},
"/isEven": { "/isEven": {
"post": { "post": {
"summary": "Checks if number is even", "summary": "Checks if number is even",
@@ -239,6 +287,266 @@
} }
} }
} }
},
"/add": {
"post": {
"summary": "Adds two numbers",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "object",
"properties": {
"a": {
"type": "number",
"example": 5
},
"b": {
"type": "number",
"example": 10
}
}
}
}
}
}
}
},
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/add/{a}/{b}": {
"get": {
"summary": "Adds two numbers from path parameters",
"parameters": [
{
"name": "a",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"example": "5"
},
{
"name": "b",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"example": "10"
}
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/subtract": {
"post": {
"summary": "Subtracts second number from first",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "object",
"properties": {
"a": {
"type": "number",
"example": 10
},
"b": {
"type": "number",
"example": 5
}
}
}
}
}
}
}
},
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/subtract/{a}/{b}": {
"get": {
"summary": "Subtracts second number from first from path parameters",
"parameters": [
{
"name": "a",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"example": "10"
},
{
"name": "b",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"example": "5"
}
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/multiply": {
"post": {
"summary": "Multiplies two numbers",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "object",
"properties": {
"a": {
"type": "number",
"example": 5
},
"b": {
"type": "number",
"example": 10
}
}
}
}
}
}
}
},
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/multiply/{a}/{b}": {
"get": {
"summary": "Multiplies two numbers from path parameters",
"parameters": [
{
"name": "a",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"example": "5"
},
{
"name": "b",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"example": "10"
}
],
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/divide": {
"post": {
"summary": "Divides first number by second",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"input": {
"type": "object",
"properties": {
"a": {
"type": "number",
"example": 10
},
"b": {
"type": "number",
"example": 2
}
}
}
}
}
}
}
},
"responses": {
"200": {
"description": "Success"
}
}
}
},
"/divide/{a}/{b}": {
"get": {
"summary": "Divides first number by second from path parameters",
"parameters": [
{
"name": "a",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"example": "10"
},
{
"name": "b",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"example": "2"
}
],
"responses": {
"200": {
"description": "Success"
}
}
}
} }
} }
} }

View File

@@ -2,11 +2,18 @@ const express = require('express');
const bodyParser = require('body-parser'); const bodyParser = require('body-parser');
const path = require('path'); const path = require('path');
const sortRoute = require('./routes/api/sort'); const sortRoute = require('./routes/api/sort');
const stalinSortRoute = require('./routes/api/stalinSort');
const isEvenRoute = require('./routes/api/isEven'); const isEvenRoute = require('./routes/api/isEven');
const isOddRoute = require('./routes/api/isOdd'); const isOddRoute = require('./routes/api/isOdd');
const toStringRoute = require('./routes/api/toString'); const toStringRoute = require('./routes/api/toString');
const isNumberRoute = require('./routes/api/isNumber'); const isNumberRoute = require('./routes/api/isNumber');
const stringSplitRoute = require('./routes/api/stringSplit'); const stringSplitRoute = require('./routes/api/stringSplit');
const addRoute = require('./routes/api/add');
const subtractRoute = require('./routes/api/subtract');
const multiplyRoute = require('./routes/api/multiply');
const divideRoute = require('./routes/api/divide');
const docsRoute = require('./routes/docs/main'); const docsRoute = require('./routes/docs/main');
const app = express(); const app = express();
@@ -17,11 +24,18 @@ app.use(express.static(path.join(__dirname, '../www')));
app.use(bodyParser.json()); app.use(bodyParser.json());
app.use('/api/sort', sortRoute); app.use('/api/sort', sortRoute);
app.use('/api/stalinSort', stalinSortRoute);
app.use('/api/isEven', isEvenRoute); app.use('/api/isEven', isEvenRoute);
app.use('/api/isOdd', isOddRoute); app.use('/api/isOdd', isOddRoute);
app.use('/api/toString', toStringRoute); app.use('/api/toString', toStringRoute);
app.use('/api/isNumber', isNumberRoute); app.use('/api/isNumber', isNumberRoute);
app.use('/api/stringSplit', stringSplitRoute); app.use('/api/stringSplit', stringSplitRoute);
app.use('/api/add', addRoute);
app.use('/api/subtract', subtractRoute);
app.use('/api/multiply', multiplyRoute);
app.use('/api/divide', divideRoute);
app.use('/docs', docsRoute); app.use('/docs', docsRoute);
app.listen(PORT, () => { app.listen(PORT, () => {