6 Commits

Author SHA1 Message Date
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
8 changed files with 196 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
FROM node:20
FROM node:24.14
# Arbeitsverzeichnis
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;

View File

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

@@ -6,6 +6,10 @@
"description": "API Documentation for Stupid APIs"
},
"servers": [
{
"url": "/api",
"description": "Current host server"
},
{
"url": "http://localhost:3000/api",
"description": "Local server"
@@ -24,7 +28,8 @@
"properties": {
"input": {
"type": "array",
"items": {}
"items": {},
"example": [3, 1, 4, 1, 5, 9]
}
}
}
@@ -39,7 +44,7 @@
"schema": {
"type": "object",
"properties": {
"sortedArray": {
"ret": {
"type": "array",
"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": {
"post": {
"summary": "Checks if number is even",
@@ -239,6 +287,71 @@
}
}
}
},
"/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"
}
}
}
}
}
}

View File

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