Compare commits
7 Commits
f8c4e3c688
...
v1.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5be3d127bb | ||
|
|
aacb2f4287 | ||
|
|
d1edd55b36 | ||
|
|
093bdd3625 | ||
|
|
c0f81934be | ||
|
|
1924b1d262 | ||
|
|
9228ebbe5b |
28
.gitea/workflows/release.yml
Normal file
28
.gitea/workflows/release.yml
Normal 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 }}
|
||||
@@ -1,5 +1,5 @@
|
||||
# Basis-Image
|
||||
FROM node:20
|
||||
FROM node:24.14
|
||||
|
||||
# Arbeitsverzeichnis
|
||||
WORKDIR /app
|
||||
|
||||
23
nginx.conf
23
nginx.conf
@@ -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
14
src/routes/api/add.js
Normal 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
14
src/routes/api/divide.js
Normal 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/multiply.js
Normal file
14
src/routes/api/multiply.js
Normal 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;
|
||||
|
||||
@@ -15,7 +15,7 @@ router.post('/', (req, res) => {
|
||||
return String(a).localeCompare(String(b));
|
||||
});
|
||||
|
||||
res.json({ sortedArray });
|
||||
res.json({ ret: sortedArray });
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
29
src/routes/api/stalinSort.js
Normal file
29
src/routes/api/stalinSort.js
Normal 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;
|
||||
14
src/routes/api/subtract.js
Normal file
14
src/routes/api/subtract.js
Normal 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;
|
||||
|
||||
@@ -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,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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,18 @@ 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 subtractRoute = require('./routes/api/subtract');
|
||||
const multiplyRoute = require('./routes/api/multiply');
|
||||
const divideRoute = require('./routes/api/divide');
|
||||
|
||||
|
||||
const docsRoute = require('./routes/docs/main');
|
||||
|
||||
const app = express();
|
||||
@@ -17,11 +24,18 @@ 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('/api/subtract', subtractRoute);
|
||||
app.use('/api/multiply', multiplyRoute);
|
||||
app.use('/api/divide', divideRoute);
|
||||
|
||||
|
||||
app.use('/docs', docsRoute);
|
||||
|
||||
app.listen(PORT, () => {
|
||||
|
||||
Reference in New Issue
Block a user