mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
General optimations
This commit is contained in:
16
roles/web-svc-simpleicons/templates/Dockerfile.j2
Normal file
16
roles/web-svc-simpleicons/templates/Dockerfile.j2
Normal file
@@ -0,0 +1,16 @@
|
||||
FROM node:latest AS builder
|
||||
|
||||
WORKDIR /app
|
||||
COPY ./config/package*.json ./
|
||||
|
||||
RUN npm install
|
||||
|
||||
FROM node:latest
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY ./config/server.js .
|
||||
|
||||
EXPOSE {{ container_port }}
|
||||
|
||||
CMD ["node", "server.js"]
|
14
roles/web-svc-simpleicons/templates/docker-compose.yml.j2
Normal file
14
roles/web-svc-simpleicons/templates/docker-compose.yml.j2
Normal file
@@ -0,0 +1,14 @@
|
||||
{% include 'roles/docker-compose/templates/base.yml.j2' %}
|
||||
application:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: simpleicons-server:latest
|
||||
container_name: simpleicons-server
|
||||
ports:
|
||||
- "{{ports.localhost.http[application_id]}}:{{ container_port }}"
|
||||
{% include 'roles/docker-container/templates/base.yml.j2' %}
|
||||
{% include 'roles/docker-container/templates/networks.yml.j2' %}
|
||||
{% include 'roles/docker-container/templates/healthcheck/curl.yml.j2' %}
|
||||
|
||||
{% include 'roles/docker-compose/templates/networks.yml.j2' %}
|
1
roles/web-svc-simpleicons/templates/env.j2
Normal file
1
roles/web-svc-simpleicons/templates/env.j2
Normal file
@@ -0,0 +1 @@
|
||||
{# This file just exists, because the framework requests it. #}
|
9
roles/web-svc-simpleicons/templates/package.json.j2
Normal file
9
roles/web-svc-simpleicons/templates/package.json.j2
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "simpleicons-server",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"express": "*",
|
||||
"simple-icons": "*",
|
||||
"sharp": "*"
|
||||
}
|
||||
}
|
62
roles/web-svc-simpleicons/templates/server.js.j2
Normal file
62
roles/web-svc-simpleicons/templates/server.js.j2
Normal file
@@ -0,0 +1,62 @@
|
||||
import express from 'express';
|
||||
import * as icons from 'simple-icons';
|
||||
import sharp from 'sharp';
|
||||
|
||||
const app = express();
|
||||
const port = {{ container_port }};
|
||||
|
||||
// Helper: convert 'nextcloud' → 'siNextcloud'
|
||||
function getExportName(slug) {
|
||||
return 'si' + slug
|
||||
.split('-')
|
||||
.map(part => part[0].toUpperCase() + part.slice(1))
|
||||
.join('');
|
||||
}
|
||||
|
||||
// Root: redirect to your documentation
|
||||
app.get('/', (req, res) => {
|
||||
res.redirect('{{ domains | get_url('sphinx', web_protocol) }}/roles/web-app-{{ application_id }}/README.html');
|
||||
});
|
||||
|
||||
// GET /:slug.svg
|
||||
app.get('/:slug.svg', (req, res) => {
|
||||
const slug = req.params.slug.toLowerCase();
|
||||
const exportName = getExportName(slug);
|
||||
const icon = icons[exportName];
|
||||
|
||||
if (!icon) {
|
||||
return res.status(404).send('Icon not found');
|
||||
}
|
||||
|
||||
res.type('image/svg+xml');
|
||||
res.send(icon.svg);
|
||||
});
|
||||
|
||||
// GET /:slug.png?size=...
|
||||
app.get('/:slug.png', async (req, res) => {
|
||||
const slug = req.params.slug.toLowerCase();
|
||||
const size = parseInt(req.query.size, 10) || 128;
|
||||
const exportName = getExportName(slug);
|
||||
const icon = icons[exportName];
|
||||
|
||||
if (!icon) {
|
||||
return res.status(404).send('Icon not found');
|
||||
}
|
||||
|
||||
try {
|
||||
const pngBuffer = await sharp(Buffer.from(icon.svg))
|
||||
.resize(size, size)
|
||||
.png()
|
||||
.toBuffer();
|
||||
|
||||
res.type('image/png');
|
||||
res.send(pngBuffer);
|
||||
} catch (err) {
|
||||
console.error('PNG generation error:', err);
|
||||
res.status(500).send('PNG generation error');
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Simple-Icons server listening at http://0.0.0.0:${port}`);
|
||||
});
|
Reference in New Issue
Block a user