Skip to content

Commit

Permalink
feat: WIP - On the fly svg to png converter
Browse files Browse the repository at this point in the history
  • Loading branch information
kumy committed Aug 30, 2024
1 parent fb551e7 commit ed4c50f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM nginx
FROM nginx:alpine-perl

RUN apk add --no-cache rsvg-convert

COPY files/ /
RUN rm -f /usr/share/nginx/html/index.html
Expand Down
25 changes: 24 additions & 1 deletion files/etc/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,33 @@ server {
return 301 https://minio.geokrety.org/statpic/$user_id.png;
}

location ~* \.(eot|ttf|woff|woff2|js|css|jpg|jpeg|png|svg|gif|json)$ {
location ~* \.svg\.png$ {
root /usr/share/nginx/html;
add_header Access-Control-Allow-Origin *;
proxy_hide_header 'Cache-Control';
add_header 'Cache-Control' "public, max-age=604800";

perl 'sub {
my $r = shift;
my $fn = $r->filename;
$fn =~ s{\.[^.]+$}{};

if (!-e $fn) {
$r->print($fn, " does not exist!");
$r->status(404);
return OK;
}
$r->send_http_header("image/png");
$r->print(`/usr/bin/rsvg-convert $fn`);
return OK;
}';
}

location ~* \.(eot|ttf|woff|woff2|js|css|jpg|jpeg|png|gif|json)$ {
root /usr/share/nginx/html;
add_header Access-Control-Allow-Origin *;
proxy_hide_header 'Cache-Control';
add_header 'Cache-Control' "public, max-age=604800";
}

}
33 changes: 33 additions & 0 deletions files/etc/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load_module /usr/lib/nginx/modules/ngx_http_perl_module.so;

user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;
}

0 comments on commit ed4c50f

Please sign in to comment.