mirror of
https://github.com/theoleuthardt/werkzeugkiste.git
synced 2026-06-13 09:37:53 +00:00
Merge branch 'main' into feat/qr-code-generator
This commit is contained in:
commit
5cdfc5b861
7 changed files with 148 additions and 8 deletions
|
|
@ -7,6 +7,7 @@ import { passwordGenerate } from "./src/routes/passwordgenerate.route";
|
|||
import { regexTest } from "./src/routes/regextest.route";
|
||||
import { tmzConvert } from "./src/routes/tmzconvert.route";
|
||||
import { generateQRCode } from "./src/routes/generateqrcode.route";
|
||||
import { wordCounter } from "./src/routes/wordcounter.route";
|
||||
|
||||
const app = Fastify({ logger: true });
|
||||
|
||||
|
|
@ -23,6 +24,7 @@ app.register(passwordGenerate);
|
|||
app.register(regexTest);
|
||||
app.register(tmzConvert);
|
||||
app.register(generateQRCode);
|
||||
app.register(wordCounter);
|
||||
|
||||
const PORT = process.env.PORT || 4000;
|
||||
app.listen({ port: Number(PORT), host: "0.0.0.0" }, () => {
|
||||
|
|
|
|||
|
|
@ -34,12 +34,12 @@ export async function regexTest(app: FastifyInstance) {
|
|||
}
|
||||
|
||||
const result = regexPattern.test(data.test);
|
||||
|
||||
|
||||
let output = "";
|
||||
if (result) {
|
||||
output = `The input matches the regular expression!`;
|
||||
output = "The input matches the regular expression!";
|
||||
} else {
|
||||
output = `The input does not match the regular expression.`;
|
||||
output = "The input does not match the regular expression.";
|
||||
}
|
||||
|
||||
reply.header("Content-Type", "text/plain").status(200).send(output);
|
||||
|
|
|
|||
34
backend/src/routes/wordcounter.route.ts
Normal file
34
backend/src/routes/wordcounter.route.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
||||
|
||||
interface RequestBody {
|
||||
input: string;
|
||||
}
|
||||
|
||||
export async function wordCounter(app: FastifyInstance) {
|
||||
app.post(
|
||||
"/api/word-counter",
|
||||
async (
|
||||
request: FastifyRequest<{ Body: RequestBody }>,
|
||||
reply: FastifyReply,
|
||||
) => {
|
||||
try {
|
||||
const data = request.body;
|
||||
if (!data) {
|
||||
return reply.status(400).send({ error: "No text declared!" });
|
||||
} else if (data.input == "") {
|
||||
return reply.status(400).send({ error: "No text!" });
|
||||
}
|
||||
|
||||
const output = data.input.trim().split(/\s+/).length;
|
||||
|
||||
reply
|
||||
.header("Content-Type", "text/plain")
|
||||
.status(200)
|
||||
.send(output.toString());
|
||||
} catch (error) {
|
||||
console.error("Convert error:", error);
|
||||
reply.status(500).send({ error: "Error while converting!" });
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue