mirror of
https://github.com/theoleuthardt/werkzeugkiste.git
synced 2026-06-13 09:37:53 +00:00
Merge branch 'main' into feat/doc-converter
This commit is contained in:
commit
8fe6657200
14 changed files with 315 additions and 27 deletions
3
backend/.prettierignore
Normal file
3
backend/.prettierignore
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Ignore artifacts:
|
||||
build
|
||||
coverage
|
||||
1
backend/.prettierrc
Normal file
1
backend/.prettierrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
{}
|
||||
54
backend/Dockerfile
Normal file
54
backend/Dockerfile
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# Basis-Image
|
||||
FROM node:18-alpine AS base
|
||||
|
||||
# Install system dependencies
|
||||
RUN apk add --no-cache libc6-compat libreoffice ttf-liberation
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Dependencies installieren
|
||||
FROM base AS deps
|
||||
COPY package.json package-lock.json* yarn.lock* pnpm-lock.yaml* ./
|
||||
|
||||
RUN \
|
||||
if [ -f yarn.lock ]; then yarn install --frozen-lockfile; \
|
||||
elif [ -f package-lock.json ]; then npm ci; \
|
||||
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm install --frozen-lockfile; \
|
||||
else echo "Lockfile not found." && exit 1; \
|
||||
fi
|
||||
|
||||
# Build stage
|
||||
FROM base AS builder
|
||||
WORKDIR /app
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . /app
|
||||
|
||||
RUN \
|
||||
if [ -f yarn.lock ]; then yarn run build; \
|
||||
elif [ -f package-lock.json ]; then npm run build; \
|
||||
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
|
||||
else echo "Lockfile not found." && exit 1; \
|
||||
fi
|
||||
|
||||
# Production image
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV=production
|
||||
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 fastify
|
||||
|
||||
# Copy built application
|
||||
COPY --from=builder --chown=fastify:nodejs /app/dist ./dist
|
||||
COPY --from=deps --chown=fastify:nodejs /app/node_modules ./node_modules
|
||||
COPY --from=builder --chown=fastify:nodejs /app/package.json ./package.json
|
||||
|
||||
USER fastify
|
||||
|
||||
EXPOSE 4000
|
||||
|
||||
ENV PORT=4000
|
||||
ENV HOSTNAME="0.0.0.0"
|
||||
|
||||
CMD ["node", "dist/server.js"]
|
||||
17
backend/package-lock.json
generated
17
backend/package-lock.json
generated
|
|
@ -19,6 +19,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.13.4",
|
||||
"prettier": "3.5.1",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.7.3"
|
||||
}
|
||||
|
|
@ -758,6 +759,22 @@
|
|||
"integrity": "sha512-e906FRY0+tV27iq4juKzSYPbUj2do2X2JX4EzSca1631EB2QJQUqGbDuERal7LCtOpxl6x3+nvo9NPZcmjkiFA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "3.5.1",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.1.tgz",
|
||||
"integrity": "sha512-hPpFQvHwL3Qv5AdRvBFMhnKo4tYxp0ReXiPn2bxkiohEX6mBeBwEpBSQTkD458RaaDKQMYSp4hX4UtfUTA5wDw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"prettier": "bin/prettier.cjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/process-warning": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/process-warning/-/process-warning-4.0.1.tgz",
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.13.4",
|
||||
"prettier": "3.5.1",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.7.3"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
import Fastify from "fastify";
|
||||
import cors from "@fastify/cors";
|
||||
import multipart from '@fastify/multipart';
|
||||
import multipart from "@fastify/multipart";
|
||||
import { libreConvert } from "./src/routes/libreconvert.route";
|
||||
import { colorConvert } from "./src/routes/colorconvert.route";
|
||||
|
||||
const app = Fastify({ logger: true });
|
||||
|
||||
app.register(cors, { origin: "*", exposedHeaders: 'Content-Disposition' });
|
||||
app.register(multipart);
|
||||
app.register(libreConvert);
|
||||
app.register(colorConvert);
|
||||
|
||||
const PORT = process.env.PORT || 4000;
|
||||
app.listen({ port: Number(PORT), host: "0.0.0.0" }, () => {
|
||||
console.log(`🚀Fastify is live on http://localhost:${PORT}`);
|
||||
});
|
||||
console.log(`🚀Fastify is live on http://localhost:${PORT}`);
|
||||
});
|
||||
|
|
|
|||
29
backend/src/routes/colorconvert.route.ts
Normal file
29
backend/src/routes/colorconvert.route.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
||||
|
||||
interface RequestBody {
|
||||
red: string;
|
||||
green: string;
|
||||
blue: string;
|
||||
}
|
||||
|
||||
export async function colorConvert(app: FastifyInstance) {
|
||||
app.post(
|
||||
"/api/color-convert",
|
||||
async (
|
||||
request: FastifyRequest<{ Body: RequestBody }>,
|
||||
reply: FastifyReply,
|
||||
) => {
|
||||
try {
|
||||
const data = request.body;
|
||||
if (!data) {
|
||||
return reply.status(400).send({ error: "No RGB declared!" });
|
||||
}
|
||||
const hex = (`#${(+data.red).toString(16).padStart(2, "0")}${(+data.green).toString(16).padStart(2, "0")}${(+data.blue).toString(16).padStart(2, "0")}`).toUpperCase();
|
||||
reply.header("Content-Type", "application/json").send({ hex: hex });
|
||||
} catch (error) {
|
||||
console.error("Convert error:", error);
|
||||
reply.status(500).send({ error: "Error while converting!" });
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
@ -62,4 +62,4 @@ export async function libreConvert(app: FastifyInstance) {
|
|||
reply.status(500).send({ error: "Error while converting!" });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
"target": "ES6",
|
||||
"module": "CommonJS",
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"rootDir": ".",
|
||||
"strict": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue