diff --git a/backend/server.ts b/backend/server.ts index 607a74c..8973a64 100644 --- a/backend/server.ts +++ b/backend/server.ts @@ -6,6 +6,7 @@ import { colorConvert } from "./src/routes/colorconvert.route"; import { passwordGenerate } from "./src/routes/passwordgenerate.route"; import { regexTest } from "./src/routes/regextest.route"; import { tmzConvert } from "./src/routes/tmzconvert.route"; +import { wordCounter } from "./src/routes/wordcounter.route"; const app = Fastify({ logger: true }); @@ -21,6 +22,7 @@ app.register(colorConvert); app.register(passwordGenerate); app.register(regexTest); app.register(tmzConvert); +app.register(wordCounter); const PORT = process.env.PORT || 4000; app.listen({ port: Number(PORT), host: "0.0.0.0" }, () => { diff --git a/backend/src/routes/regextest.route.ts b/backend/src/routes/regextest.route.ts index 7f08bd6..025a3ef 100644 --- a/backend/src/routes/regextest.route.ts +++ b/backend/src/routes/regextest.route.ts @@ -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); diff --git a/backend/src/routes/wordcounter.route.ts b/backend/src/routes/wordcounter.route.ts new file mode 100644 index 0000000..3b747ac --- /dev/null +++ b/backend/src/routes/wordcounter.route.ts @@ -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!" }); + } + }, + ); +} diff --git a/frontend/src/app/password-generator/page.tsx b/frontend/src/app/password-generator/page.tsx index eda0f9e..138fba1 100644 --- a/frontend/src/app/password-generator/page.tsx +++ b/frontend/src/app/password-generator/page.tsx @@ -5,7 +5,7 @@ import Navbar from "../../components/Navbar"; import Footer from "../../components/Footer"; import Button from "../../components/Button"; -export default function RgbToHex() { +export default function PasswordGenerator() { const [loading, setLoading] = useState(false); const [password, setPassword] = useState(""); diff --git a/frontend/src/app/rgb-to-hex/page.tsx b/frontend/src/app/rgb-to-hex/page.tsx index a80141d..aa1825d 100644 --- a/frontend/src/app/rgb-to-hex/page.tsx +++ b/frontend/src/app/rgb-to-hex/page.tsx @@ -71,7 +71,7 @@ export default function RgbToHex() {