Compare commits
10 Commits
8ac8643e6d
...
v1.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 19c477aa05 | |||
| 5be3d127bb | |||
| aacb2f4287 | |||
| d1edd55b36 | |||
| 093bdd3625 | |||
| c0f81934be | |||
| 1924b1d262 | |||
| 9228ebbe5b | |||
| f8c4e3c688 | |||
| 88ef8136f3 |
@@ -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 }}
|
||||||
@@ -2,3 +2,5 @@ node_modules
|
|||||||
test.*
|
test.*
|
||||||
*.log
|
*.log
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
|
package-lock.json
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
# Basis-Image
|
# Basis-Image
|
||||||
FROM node:20
|
FROM node:24.14
|
||||||
|
|
||||||
# Arbeitsverzeichnis
|
# Arbeitsverzeichnis
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|||||||
-158
@@ -1,158 +0,0 @@
|
|||||||
|
|
||||||
# 📄 API Documentation – **Stupid APIs**
|
|
||||||
|
|
||||||
## Base URL
|
|
||||||
|
|
||||||
```
|
|
||||||
http://localhost:3000/api
|
|
||||||
```
|
|
||||||
|
|
||||||
**Default Headers:**
|
|
||||||
|
|
||||||
```
|
|
||||||
Content-Type: application/json
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## POST `/sort`
|
|
||||||
|
|
||||||
Sorts an array (numeric or alphabetical) and returns the sorted array.
|
|
||||||
|
|
||||||
### Request
|
|
||||||
|
|
||||||
**URL:**
|
|
||||||
|
|
||||||
```
|
|
||||||
POST /sort
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
**Body Example:**
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"input": [3, 1, 4, 1, 5, 9]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Successful Response
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"sortedArray": [1, 1, 3, 4, 5, 9]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## POST `/isOdd`
|
|
||||||
|
|
||||||
Checks if a given number is odd.
|
|
||||||
|
|
||||||
### Request
|
|
||||||
|
|
||||||
**URL:**
|
|
||||||
|
|
||||||
```
|
|
||||||
POST /isOdd
|
|
||||||
```
|
|
||||||
|
|
||||||
**Body Example:**
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"input": 7
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Successful Response
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"ret": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## POST `/isEven`
|
|
||||||
|
|
||||||
Checks if a given number is even.
|
|
||||||
|
|
||||||
### Request
|
|
||||||
|
|
||||||
**URL:**
|
|
||||||
|
|
||||||
```
|
|
||||||
POST /isEven
|
|
||||||
```
|
|
||||||
|
|
||||||
**Body Example:**
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"input": 4
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Successful Response
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"ret": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## POST `/toString`
|
|
||||||
|
|
||||||
calls .toString()
|
|
||||||
|
|
||||||
### Request
|
|
||||||
|
|
||||||
**URL:**
|
|
||||||
|
|
||||||
```
|
|
||||||
POST /toString
|
|
||||||
```
|
|
||||||
|
|
||||||
**Body Example:**
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"input": 7
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Successful Response
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"ret": "7"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 📌 Example Usage with `curl`
|
|
||||||
|
|
||||||
### Sort an array (Linux/macOS)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -X POST http://localhost:3000/sort \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{"array":[3,1,4,1,5,9]}'
|
|
||||||
```
|
|
||||||
|
|
||||||
### Check if odd
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -X POST http://localhost:3000/is-odd \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{"number":7}'
|
|
||||||
```
|
|
||||||
|
|
||||||
### Check if even
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -X POST http://localhost:3000/is-even \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{"number":4}'
|
|
||||||
```
|
|
||||||
-23
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Generated
+1258
File diff suppressed because it is too large
Load Diff
+3
-3
@@ -7,11 +7,11 @@
|
|||||||
"start": "node src/server.js"
|
"start": "node src/server.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.18.2",
|
|
||||||
"body-parser": "^1.20.2",
|
"body-parser": "^1.20.2",
|
||||||
|
"express": "^4.18.2",
|
||||||
"is-even": "^1.0.0",
|
"is-even": "^1.0.0",
|
||||||
"is-odd": "^3.0.1",
|
"is-odd": "^3.0.1",
|
||||||
"showdown": "^2.1.0",
|
"swagger-jsdoc": "^6.2.8",
|
||||||
"fs": "^0.0.1-security"
|
"swagger-ui-express": "^5.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
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: 'input must be an array' });
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json({ ret: [...input].reverse() });
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -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;
|
||||||
@@ -4,13 +4,11 @@ const router = express.Router();
|
|||||||
|
|
||||||
router.post('/', (req, res) => {
|
router.post('/', (req, res) => {
|
||||||
const { input } = req.body;
|
const { input } = req.body;
|
||||||
|
|
||||||
res.json({ ret: isEven(Number(input)) });
|
res.json({ ret: isEven(Number(input)) });
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/:number', (req, res) => {
|
router.get('/:number', (req, res) => {
|
||||||
const input = req.params.number;
|
const input = req.params.number;
|
||||||
|
|
||||||
res.json({ ret: isEven(Number(input)) });
|
res.json({ ret: isEven(Number(input)) });
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -3,14 +3,12 @@ const router = express.Router();
|
|||||||
|
|
||||||
router.post('/', (req, res) => {
|
router.post('/', (req, res) => {
|
||||||
const { input } = req.body;
|
const { input } = req.body;
|
||||||
|
res.json({ ret: !isNaN(input) });
|
||||||
res.json({ ret: ! isNaN(input) });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/:number', (req, res) => {
|
router.get('/:number', (req, res) => {
|
||||||
const input = req.params.number;
|
const input = req.params.number;
|
||||||
|
res.json({ ret: !isNaN(input) });
|
||||||
res.json({ ret: ! isNaN(input) });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
@@ -4,13 +4,11 @@ const router = express.Router();
|
|||||||
|
|
||||||
router.post('/', (req, res) => {
|
router.post('/', (req, res) => {
|
||||||
const { input } = req.body;
|
const { input } = req.body;
|
||||||
|
|
||||||
res.json({ ret: isOdd(Number(input)) });
|
res.json({ ret: isOdd(Number(input)) });
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/:number', (req, res) => {
|
router.get('/:number', (req, res) => {
|
||||||
const input = req.params.number;
|
const input = req.params.number;
|
||||||
|
|
||||||
res.json({ ret: isOdd(Number(input)) });
|
res.json({ ret: isOdd(Number(input)) });
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
// Math
|
||||||
|
router.use('/add', require('./math/add'));
|
||||||
|
router.use('/subtract', require('./math/subtract'));
|
||||||
|
router.use('/multiply', require('./math/multiply'));
|
||||||
|
router.use('/divide', require('./math/divide'));
|
||||||
|
router.use('/modulo', require('./math/modulo'));
|
||||||
|
|
||||||
|
// String
|
||||||
|
router.use('/toString', require('./string/toString'));
|
||||||
|
router.use('/stringSplit', require('./string/stringSplit'));
|
||||||
|
router.use('/reverseString', require('./string/reverseString'));
|
||||||
|
router.use('/isPalindrome', require('./string/isPalindrome'));
|
||||||
|
router.use('/stringLength', require('./string/stringLength'));
|
||||||
|
router.use('/countWords', require('./string/countWords'));
|
||||||
|
router.use('/toUpperCase', require('./string/toUpperCase'));
|
||||||
|
router.use('/toLowerCase', require('./string/toLowerCase'));
|
||||||
|
|
||||||
|
// Array
|
||||||
|
router.use('/sort', require('./array/sort'));
|
||||||
|
router.use('/reverseArray', require('./array/reverseArray'));
|
||||||
|
|
||||||
|
// Checks
|
||||||
|
router.use('/isEven', require('./checks/isEven'));
|
||||||
|
router.use('/isOdd', require('./checks/isOdd'));
|
||||||
|
router.use('/isNumber', require('./checks/isNumber'));
|
||||||
|
|
||||||
|
// Meme sorts
|
||||||
|
router.use('/stalinSort', require('./sorts/stalinSort'));
|
||||||
|
router.use('/bogoSort', require('./sorts/bogoSort'));
|
||||||
|
router.use('/thanoSort', require('./sorts/thanoSort'));
|
||||||
|
router.use('/sleepSort', require('./sorts/sleepSort'));
|
||||||
|
router.use('/miracleSort', require('./sorts/miracleSort'));
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
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;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
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;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
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;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
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;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
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;
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
function isSorted(arr) {
|
||||||
|
for (let i = 1; i < arr.length; i++) {
|
||||||
|
if (arr[i] < arr[i - 1]) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function shuffle(arr) {
|
||||||
|
const a = [...arr];
|
||||||
|
for (let i = a.length - 1; i > 0; i--) {
|
||||||
|
const j = Math.floor(Math.random() * (i + 1));
|
||||||
|
[a[i], a[j]] = [a[j], a[i]];
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.post('/', (req, res) => {
|
||||||
|
const { input } = req.body;
|
||||||
|
|
||||||
|
if (!Array.isArray(input)) {
|
||||||
|
return res.status(400).json({ error: 'input must be an array' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const MAX_ATTEMPTS = 1000;
|
||||||
|
let arr = [...input];
|
||||||
|
let attempts = 0;
|
||||||
|
|
||||||
|
while (!isSorted(arr) && attempts < MAX_ATTEMPTS) {
|
||||||
|
arr = shuffle(arr);
|
||||||
|
attempts++;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
ret: arr,
|
||||||
|
attempts,
|
||||||
|
success: isSorted(arr)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
function isSorted(arr) {
|
||||||
|
for (let i = 1; i < arr.length; i++) {
|
||||||
|
if (arr[i] < arr[i - 1]) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.post('/', (req, res) => {
|
||||||
|
const { input } = req.body;
|
||||||
|
|
||||||
|
if (!Array.isArray(input)) {
|
||||||
|
return res.status(400).json({ error: 'input must be an array' });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSorted(input)) {
|
||||||
|
res.json({ ret: input, miracle: true, message: 'A miracle has occurred!' });
|
||||||
|
} else {
|
||||||
|
res.json({ ret: input, miracle: false, message: 'Waiting for cosmic miracle... Please try again later.' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
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: 'input must be an array' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const sorted = [...input].sort((a, b) => a - b);
|
||||||
|
const totalSleepMs = input.reduce((sum, n) => sum + Math.abs(Number(n)), 0);
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
ret: sorted,
|
||||||
|
totalSleepTimeMs: totalSleepMs,
|
||||||
|
note: "We simulated the sleep. You're welcome."
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -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;
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
function isSorted(arr) {
|
||||||
|
for (let i = 1; i < arr.length; i++) {
|
||||||
|
if (arr[i] < arr[i - 1]) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.post('/', (req, res) => {
|
||||||
|
const { input } = req.body;
|
||||||
|
|
||||||
|
if (!Array.isArray(input)) {
|
||||||
|
return res.status(400).json({ error: 'input must be an array' });
|
||||||
|
}
|
||||||
|
|
||||||
|
let arr = [...input];
|
||||||
|
let snaps = 0;
|
||||||
|
|
||||||
|
while (!isSorted(arr) && arr.length > 1) {
|
||||||
|
const survivors = Math.ceil(arr.length / 2);
|
||||||
|
const indices = new Set();
|
||||||
|
while (indices.size < survivors) {
|
||||||
|
indices.add(Math.floor(Math.random() * arr.length));
|
||||||
|
}
|
||||||
|
arr = arr.filter((_, i) => indices.has(i));
|
||||||
|
snaps++;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
ret: arr,
|
||||||
|
snaps,
|
||||||
|
perfectly_balanced: isSorted(arr)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
function countWords(str) {
|
||||||
|
return String(str).trim().split(/\s+/).filter(w => w.length > 0).length;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.post('/', (req, res) => {
|
||||||
|
const { input } = req.body;
|
||||||
|
res.json({ ret: countWords(input) });
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get('/:string', (req, res) => {
|
||||||
|
res.json({ ret: countWords(req.params.string) });
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
function checkPalindrome(str) {
|
||||||
|
const clean = String(str).toLowerCase().replace(/[^a-z0-9]/g, '');
|
||||||
|
return clean === clean.split('').reverse().join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
router.post('/', (req, res) => {
|
||||||
|
const { input } = req.body;
|
||||||
|
res.json({ ret: checkPalindrome(input) });
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get('/:string', (req, res) => {
|
||||||
|
res.json({ ret: checkPalindrome(req.params.string) });
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
router.post('/', (req, res) => {
|
||||||
|
const { input } = req.body;
|
||||||
|
res.json({ ret: String(input).split('').reverse().join('') });
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get('/:string', (req, res) => {
|
||||||
|
res.json({ ret: req.params.string.split('').reverse().join('') });
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
router.post('/', (req, res) => {
|
||||||
|
const { input } = req.body;
|
||||||
|
res.json({ ret: String(input).length });
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get('/:string', (req, res) => {
|
||||||
|
res.json({ ret: req.params.string.length });
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -3,7 +3,6 @@ const router = express.Router();
|
|||||||
|
|
||||||
router.post('/', (req, res) => {
|
router.post('/', (req, res) => {
|
||||||
const { input } = req.body;
|
const { input } = req.body;
|
||||||
|
|
||||||
res.json({ ret: input.string.toString().split(input.seperator) });
|
res.json({ ret: input.string.toString().split(input.seperator) });
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
router.post('/', (req, res) => {
|
||||||
|
const { input } = req.body;
|
||||||
|
res.json({ ret: String(input).toLowerCase() });
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get('/:string', (req, res) => {
|
||||||
|
res.json({ ret: req.params.string.toLowerCase() });
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -3,7 +3,6 @@ const router = express.Router();
|
|||||||
|
|
||||||
router.post('/', (req, res) => {
|
router.post('/', (req, res) => {
|
||||||
const { input } = req.body;
|
const { input } = req.body;
|
||||||
|
|
||||||
res.json({ ret: input.toString() });
|
res.json({ ret: input.toString() });
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
router.post('/', (req, res) => {
|
||||||
|
const { input } = req.body;
|
||||||
|
res.json({ ret: String(input).toUpperCase() });
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get('/:string', (req, res) => {
|
||||||
|
res.json({ ret: req.params.string.toUpperCase() });
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
+4
-36
@@ -1,41 +1,9 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const showdown = require('showdown');
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
const converter = new showdown.Converter({
|
|
||||||
tables: true, // Tabellen-Unterstützung aktivieren
|
|
||||||
ghCompatibleHeaderId: true,
|
|
||||||
simpleLineBreaks: true,
|
|
||||||
emoji: true
|
|
||||||
});
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
const swaggerUi = require('swagger-ui-express');
|
||||||
|
const openAPI = require('./openapi.json');
|
||||||
|
|
||||||
router.get('/', (req, res) => {
|
router.use('/', swaggerUi.serve);
|
||||||
const filePath = path.join(__dirname, '../../../doc/api.md');
|
router.get('/', swaggerUi.setup(openAPI));
|
||||||
|
|
||||||
fs.readFile(filePath, 'utf-8', (err, data) => {
|
|
||||||
if (err) {
|
|
||||||
console.error(err);
|
|
||||||
return res.status(500).send("Fehler beim Laden der Markdown-Datei");
|
|
||||||
}
|
|
||||||
|
|
||||||
const htmlContent = converter.makeHtml(data);
|
|
||||||
res.set('Content-Type', 'text/html; charset=utf-8');
|
|
||||||
res.send(`<!doctype html>
|
|
||||||
<html lang="de">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<title>API-Dokumentation</title>
|
|
||||||
<link rel="stylesheet" href="/css/markdown-dark.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<main class="markdown-body">
|
|
||||||
${htmlContent}
|
|
||||||
</main>
|
|
||||||
</body>
|
|
||||||
</html>`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
@@ -0,0 +1,723 @@
|
|||||||
|
{
|
||||||
|
"openapi": "3.0.0",
|
||||||
|
"info": {
|
||||||
|
"title": "Stupid APIs",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "API Documentation for Stupid APIs"
|
||||||
|
},
|
||||||
|
"servers": [
|
||||||
|
{
|
||||||
|
"url": "/api",
|
||||||
|
"description": "Current host server"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:3000/api",
|
||||||
|
"description": "Local server"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
{ "name": "Math", "description": "Basic arithmetic operations" },
|
||||||
|
{ "name": "String", "description": "String manipulation" },
|
||||||
|
{ "name": "Array", "description": "Array operations" },
|
||||||
|
{ "name": "Checks", "description": "Value checking" },
|
||||||
|
{ "name": "Sorts", "description": "Sorting algorithms (serious and meme)" }
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"/add": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["Math"],
|
||||||
|
"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": {
|
||||||
|
"tags": ["Math"],
|
||||||
|
"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": {
|
||||||
|
"tags": ["Math"],
|
||||||
|
"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": {
|
||||||
|
"tags": ["Math"],
|
||||||
|
"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": {
|
||||||
|
"tags": ["Math"],
|
||||||
|
"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": {
|
||||||
|
"tags": ["Math"],
|
||||||
|
"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": {
|
||||||
|
"tags": ["Math"],
|
||||||
|
"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": {
|
||||||
|
"tags": ["Math"],
|
||||||
|
"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" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/modulo": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["Math"],
|
||||||
|
"summary": "Calculates the remainder of a division (a % b)",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"input": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"a": { "type": "number", "example": 10 },
|
||||||
|
"b": { "type": "number", "example": 3 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/modulo/{a}/{b}": {
|
||||||
|
"get": {
|
||||||
|
"tags": ["Math"],
|
||||||
|
"summary": "Calculates the remainder 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": "3" }
|
||||||
|
],
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/toString": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["String"],
|
||||||
|
"summary": "Converts input to string",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": { "input": {} }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/stringSplit": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["String"],
|
||||||
|
"summary": "Splits a string by a separator",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"input": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"string": { "type": "string" },
|
||||||
|
"seperator": { "type": "string" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/reverseString": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["String"],
|
||||||
|
"summary": "Reverses a string",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": { "input": { "type": "string", "example": "hello" } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/reverseString/{string}": {
|
||||||
|
"get": {
|
||||||
|
"tags": ["String"],
|
||||||
|
"summary": "Reverses a string from path parameter",
|
||||||
|
"parameters": [
|
||||||
|
{ "name": "string", "in": "path", "required": true, "schema": { "type": "string" }, "example": "hello" }
|
||||||
|
],
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/isPalindrome": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["String"],
|
||||||
|
"summary": "Checks if a string is a palindrome",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": { "input": { "type": "string", "example": "racecar" } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/isPalindrome/{string}": {
|
||||||
|
"get": {
|
||||||
|
"tags": ["String"],
|
||||||
|
"summary": "Checks if a string is a palindrome from path parameter",
|
||||||
|
"parameters": [
|
||||||
|
{ "name": "string", "in": "path", "required": true, "schema": { "type": "string" }, "example": "racecar" }
|
||||||
|
],
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/stringLength": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["String"],
|
||||||
|
"summary": "Returns the length of a string",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": { "input": { "type": "string", "example": "hello" } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/stringLength/{string}": {
|
||||||
|
"get": {
|
||||||
|
"tags": ["String"],
|
||||||
|
"summary": "Returns the length of a string from path parameter",
|
||||||
|
"parameters": [
|
||||||
|
{ "name": "string", "in": "path", "required": true, "schema": { "type": "string" }, "example": "hello" }
|
||||||
|
],
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/countWords": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["String"],
|
||||||
|
"summary": "Counts the number of words in a string",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": { "input": { "type": "string", "example": "hello world foo" } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/countWords/{string}": {
|
||||||
|
"get": {
|
||||||
|
"tags": ["String"],
|
||||||
|
"summary": "Counts the number of words from path parameter",
|
||||||
|
"parameters": [
|
||||||
|
{ "name": "string", "in": "path", "required": true, "schema": { "type": "string" }, "example": "hello world" }
|
||||||
|
],
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/toUpperCase": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["String"],
|
||||||
|
"summary": "Converts a string to uppercase",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": { "input": { "type": "string", "example": "hello" } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/toUpperCase/{string}": {
|
||||||
|
"get": {
|
||||||
|
"tags": ["String"],
|
||||||
|
"summary": "Converts a string to uppercase from path parameter",
|
||||||
|
"parameters": [
|
||||||
|
{ "name": "string", "in": "path", "required": true, "schema": { "type": "string" }, "example": "hello" }
|
||||||
|
],
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/toLowerCase": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["String"],
|
||||||
|
"summary": "Converts a string to lowercase",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": { "input": { "type": "string", "example": "HELLO" } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/toLowerCase/{string}": {
|
||||||
|
"get": {
|
||||||
|
"tags": ["String"],
|
||||||
|
"summary": "Converts a string to lowercase from path parameter",
|
||||||
|
"parameters": [
|
||||||
|
{ "name": "string", "in": "path", "required": true, "schema": { "type": "string" }, "example": "HELLO" }
|
||||||
|
],
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/sort": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["Array"],
|
||||||
|
"summary": "Sorts an array",
|
||||||
|
"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" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/reverseArray": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["Array"],
|
||||||
|
"summary": "Reverses an array",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"input": { "type": "array", "items": {}, "example": [1, 2, 3, 4, 5] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": { "200": { "description": "Reversed array" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/isEven": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["Checks"],
|
||||||
|
"summary": "Checks if number is even",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": { "type": "object", "properties": { "input": { "type": "number" } } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/isEven/{number}": {
|
||||||
|
"get": {
|
||||||
|
"tags": ["Checks"],
|
||||||
|
"summary": "Checks if number is even from path parameter",
|
||||||
|
"parameters": [
|
||||||
|
{ "name": "number", "in": "path", "required": true, "schema": { "type": "string" } }
|
||||||
|
],
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/isOdd": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["Checks"],
|
||||||
|
"summary": "Checks if number is odd",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": { "type": "object", "properties": { "input": { "type": "number" } } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/isOdd/{number}": {
|
||||||
|
"get": {
|
||||||
|
"tags": ["Checks"],
|
||||||
|
"summary": "Checks if number is odd from path parameter",
|
||||||
|
"parameters": [
|
||||||
|
{ "name": "number", "in": "path", "required": true, "schema": { "type": "string" } }
|
||||||
|
],
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/isNumber": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["Checks"],
|
||||||
|
"summary": "Checks if input is a number",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": { "type": "object", "properties": { "input": {} } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/isNumber/{number}": {
|
||||||
|
"get": {
|
||||||
|
"tags": ["Checks"],
|
||||||
|
"summary": "Checks if param is a number",
|
||||||
|
"parameters": [
|
||||||
|
{ "name": "number", "in": "path", "required": true, "schema": { "type": "string" } }
|
||||||
|
],
|
||||||
|
"responses": { "200": { "description": "Success" } }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/stalinSort": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["Sorts"],
|
||||||
|
"summary": "Sorts an array using Stalin Sort",
|
||||||
|
"description": "Elements that are not in order get purged. No re-education, just removal.",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"input": { "type": "array", "items": {}, "example": [3, 1, 4, 1, 5, 9] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Purged array and execution count",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"ret": { "type": "array", "items": {} },
|
||||||
|
"executions": { "type": "number" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/bogoSort": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["Sorts"],
|
||||||
|
"summary": "Sorts an array using Bogo Sort",
|
||||||
|
"description": "Randomly shuffles the array until it is sorted. Max 1000 attempts. Good luck.",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"input": { "type": "array", "items": {}, "example": [3, 1, 2] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Result with attempt count and success flag",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"ret": { "type": "array", "items": {} },
|
||||||
|
"attempts": { "type": "number" },
|
||||||
|
"success": { "type": "boolean" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/thanoSort": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["Sorts"],
|
||||||
|
"summary": "Sorts an array using Thanos Sort",
|
||||||
|
"description": "Randomly removes half the elements until the array is sorted. Perfectly balanced, as all things should be.",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"input": { "type": "array", "items": {}, "example": [5, 3, 1, 4, 2] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Surviving elements, snap count, and balance status",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"ret": { "type": "array", "items": {} },
|
||||||
|
"snaps": { "type": "number" },
|
||||||
|
"perfectly_balanced": { "type": "boolean" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/sleepSort": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["Sorts"],
|
||||||
|
"summary": "Sorts an array using Sleep Sort",
|
||||||
|
"description": "Each element sleeps for n milliseconds, then wakes up and joins the output. We simulated the sleep for you.",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"input": { "type": "array", "items": { "type": "number" }, "example": [3, 1, 4, 1, 5] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Sorted array with total simulated sleep time",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"ret": { "type": "array", "items": {} },
|
||||||
|
"totalSleepTimeMs": { "type": "number" },
|
||||||
|
"note": { "type": "string" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/miracleSort": {
|
||||||
|
"post": {
|
||||||
|
"tags": ["Sorts"],
|
||||||
|
"summary": "Sorts an array using Miracle Sort",
|
||||||
|
"description": "Checks if the array is already sorted. If not, it waits for a cosmic miracle. Please try again later.",
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"input": { "type": "array", "items": {}, "example": [1, 2, 3, 4, 5] }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Array with miracle status and message",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"ret": { "type": "array", "items": {} },
|
||||||
|
"miracle": { "type": "boolean" },
|
||||||
|
"message": { "type": "string" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-14
@@ -1,27 +1,16 @@
|
|||||||
const express = require('express');
|
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 isEvenRoute = require('./routes/api/isEven');
|
const apiRoutes = require('./routes/api');
|
||||||
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 docsRoute = require('./routes/docs/main');
|
const docsRoute = require('./routes/docs/main');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
const PORT = 3000;
|
const PORT = 3000;
|
||||||
|
|
||||||
app.use(express.static(path.join(__dirname, '../www')));
|
app.use(express.static(path.join(__dirname, '../www')));
|
||||||
|
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.use('/api/sort', sortRoute);
|
app.use('/api', apiRoutes);
|
||||||
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('/docs', docsRoute);
|
app.use('/docs', docsRoute);
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
|
|||||||
@@ -1,194 +0,0 @@
|
|||||||
/* markdown-dark.css */
|
|
||||||
/* Basis: neutraler Dark-Mode mit guter Lesbarkeit und sauberem Tabellenlayout */
|
|
||||||
:root {
|
|
||||||
--bg: #0d1117;
|
|
||||||
--bg-muted: #161b22;
|
|
||||||
--text: #c9d1d9;
|
|
||||||
--text-muted: #8b949e;
|
|
||||||
--border: #30363d;
|
|
||||||
--link: #58a6ff;
|
|
||||||
--code-bg: #161b22;
|
|
||||||
--code-text: #f0f6fc;
|
|
||||||
--kbd-bg: #0b1020;
|
|
||||||
--kbd-border: #30363d;
|
|
||||||
--accent: #1f6feb;
|
|
||||||
}
|
|
||||||
|
|
||||||
html, body {
|
|
||||||
background: var(--bg);
|
|
||||||
color: var(--text);
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-body {
|
|
||||||
box-sizing: border-box;
|
|
||||||
max-width: 900px;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 24px;
|
|
||||||
line-height: 1.65;
|
|
||||||
font: 16px/1.65 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Apple Color Emoji","Segoe UI Emoji";
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Überschriften */
|
|
||||||
.markdown-body h1,
|
|
||||||
.markdown-body h2,
|
|
||||||
.markdown-body h3,
|
|
||||||
.markdown-body h4,
|
|
||||||
.markdown-body h5,
|
|
||||||
.markdown-body h6 {
|
|
||||||
color: var(--text);
|
|
||||||
margin: 1.6em 0 .6em;
|
|
||||||
font-weight: 700;
|
|
||||||
line-height: 1.25;
|
|
||||||
border-bottom: 1px solid var(--border);
|
|
||||||
padding-bottom: .3em;
|
|
||||||
}
|
|
||||||
.markdown-body h1 { font-size: 2rem; }
|
|
||||||
.markdown-body h2 { font-size: 1.6rem; }
|
|
||||||
.markdown-body h3 { font-size: 1.35rem; border-bottom: none; }
|
|
||||||
.markdown-body h4 { font-size: 1.15rem; border-bottom: none; }
|
|
||||||
.markdown-body h5 { font-size: 1rem; border-bottom: none; }
|
|
||||||
.markdown-body h6 { font-size: .95rem; color: var(--text-muted); border-bottom: none; }
|
|
||||||
|
|
||||||
/* Text & Links */
|
|
||||||
.markdown-body p, .markdown-body ul, .markdown-body ol, .markdown-body blockquote, .markdown-body pre, .markdown-body table {
|
|
||||||
margin: 1em 0;
|
|
||||||
}
|
|
||||||
.markdown-body a {
|
|
||||||
color: var(--link);
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
.markdown-body a:hover, .markdown-body a:focus {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Listen */
|
|
||||||
.markdown-body ul, .markdown-body ol {
|
|
||||||
padding-left: 1.5em;
|
|
||||||
}
|
|
||||||
.markdown-body li + li {
|
|
||||||
margin-top: .25em;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Code */
|
|
||||||
.markdown-body code,
|
|
||||||
.markdown-body tt {
|
|
||||||
background: var(--code-bg);
|
|
||||||
color: var(--code-text);
|
|
||||||
padding: .15em .35em;
|
|
||||||
border-radius: 6px;
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
|
|
||||||
font-size: .95em;
|
|
||||||
}
|
|
||||||
.markdown-body pre {
|
|
||||||
background: var(--code-bg);
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 12px 14px;
|
|
||||||
overflow: auto;
|
|
||||||
}
|
|
||||||
.markdown-body pre code {
|
|
||||||
background: transparent;
|
|
||||||
border: 0;
|
|
||||||
padding: 0;
|
|
||||||
color: var(--text);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Blockquote */
|
|
||||||
.markdown-body blockquote {
|
|
||||||
border-left: 4px solid var(--border);
|
|
||||||
padding: .5em 1em;
|
|
||||||
margin-left: 0;
|
|
||||||
color: var(--text-muted);
|
|
||||||
background: rgba(22,27,34,.35);
|
|
||||||
border-radius: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Tabellen – wichtig für sauberes Layout */
|
|
||||||
.markdown-body table {
|
|
||||||
width: 100%;
|
|
||||||
border-collapse: collapse;
|
|
||||||
border-spacing: 0;
|
|
||||||
overflow: auto;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
.markdown-body thead {
|
|
||||||
background: var(--bg-muted);
|
|
||||||
}
|
|
||||||
.markdown-body th, .markdown-body td {
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
padding: 8px 12px;
|
|
||||||
text-align: left;
|
|
||||||
vertical-align: top;
|
|
||||||
}
|
|
||||||
.markdown-body th {
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
.markdown-body tr:nth-child(even) td {
|
|
||||||
background: rgba(22,27,34,.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* HR */
|
|
||||||
.markdown-body hr {
|
|
||||||
height: 1px;
|
|
||||||
border: 0;
|
|
||||||
background: var(--border);
|
|
||||||
margin: 2em 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Bilder */
|
|
||||||
.markdown-body img {
|
|
||||||
max-width: 100%;
|
|
||||||
height: auto;
|
|
||||||
border-radius: 6px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Details/Summary */
|
|
||||||
.markdown-body details {
|
|
||||||
background: var(--bg-muted);
|
|
||||||
border: 1px solid var(--border);
|
|
||||||
border-radius: 6px;
|
|
||||||
padding: .6em .9em;
|
|
||||||
}
|
|
||||||
.markdown-body summary {
|
|
||||||
cursor: pointer;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Markierung, KBD */
|
|
||||||
.markdown-body mark {
|
|
||||||
background: #99700066;
|
|
||||||
color: var(--text);
|
|
||||||
padding: 0 .2em;
|
|
||||||
border-radius: 3px;
|
|
||||||
}
|
|
||||||
.markdown-body kbd {
|
|
||||||
background: var(--kbd-bg);
|
|
||||||
border: 1px solid var(--kbd-border);
|
|
||||||
border-bottom-width: 2px;
|
|
||||||
border-radius: 6px;
|
|
||||||
padding: .1em .4em;
|
|
||||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
||||||
font-size: .85em;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Zitate/Callouts (Admonitions via blockquote) */
|
|
||||||
.markdown-body blockquote > :first-child { margin-top: 0; }
|
|
||||||
.markdown-body blockquote > :last-child { margin-bottom: 0; }
|
|
||||||
|
|
||||||
/* Inline-Abstände */
|
|
||||||
.markdown-body strong { color: var(--text); }
|
|
||||||
.markdown-body em { color: var(--text); }
|
|
||||||
|
|
||||||
/* Code-Block Scrollbar etwas dezenter */
|
|
||||||
.markdown-body pre::-webkit-scrollbar,
|
|
||||||
.markdown-body table::-webkit-scrollbar {
|
|
||||||
height: 10px;
|
|
||||||
}
|
|
||||||
.markdown-body pre::-webkit-scrollbar-thumb,
|
|
||||||
.markdown-body table::-webkit-scrollbar-thumb {
|
|
||||||
background: var(--border);
|
|
||||||
border-radius: 6px;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user