Skip to content

Commit 3a2fc78

Browse files
authored
feat: update connection pool and nginx redirects (#35)
* feat: update connection pool and nginx redirects * fix: update title passing in layout * fix: apply changes to nginx config
1 parent b94bcdc commit 3a2fc78

4 files changed

Lines changed: 33 additions & 14 deletions

File tree

src/frontend/src/app.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="%lang%">
3-
<title>Mailcom</title>
2+
<html lang="de">
43
<head>
54
<title>%sveltekit.title%</title>
65
<meta charset="utf-8" />

src/frontend/src/lib/server/db.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ if (process.env.BUILD_MODE === 'true') {
1313
db = drizzle.mock();
1414
console.log('Mock database connection created');
1515
} else {
16-
// we will use client connections since we do not expect many concurrent connections
17-
// and connection also does not need to be maintained for long
18-
const connection = await mysql.createConnection({
16+
// Use a pool instead of a single connection
17+
// Pool handles reconnection automatically
18+
const pool = mysql.createPool({
1919
host: process.env.MYSQL_HOST,
2020
port: process.env.MYSQL_PORT ? parseInt(process.env.MYSQL_PORT) : 3306,
2121
user: process.env.MYSQL_USER,
2222
password: process.env.MYSQL_PASSWORD,
2323
database: process.env.MYSQL_DATABASE,
24+
waitForConnections: true,
25+
connectionLimit: 5,
26+
queueLimit: 0,
2427
});
25-
db = drizzle(connection);
28+
db = drizzle(pool);
2629
}
2730

2831
const exportedDb = db;

src/frontend/src/routes/+layout.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
}
1717
</script>
1818

19+
<svelte:head>
20+
<title>Mailcom</title>
21+
</svelte:head>
22+
1923

2024
<nav class="bg-white border-gray-200 px-4 lg:px-6 py-2.5 relative">
2125
<div class="flex flex-wrap justify-between items-center mx-auto max-w-screen-xl">

src/nginx/conf/nginx.conf

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,29 @@ upstream app_server {
55
server {
66
listen 80 default_server;
77
listen [::]:80 default_server;
8-
server_name mailcom.rose.uni-heidelberg.de _;
8+
server_name _;
99
return 301 https://mailcom.rose.uni-heidelberg.de$request_uri;
1010
}
1111

12+
# Catch-all HTTPS: redirect any non-canonical host to domain (308 preserves POST)
1213
server {
13-
listen 443 ssl default_server;
14-
listen [::]:443 ssl default_server;
14+
listen 443 ssl;
15+
listen [::]:443 ssl;
1516
http2 on;
16-
server_name mailcom.rose.uni-heidelberg.de _;
17+
server_name _;
18+
19+
ssl_certificate /etc/nginx/ssl/mailcom.rose.uni-heidelberg.de.crt;
20+
ssl_certificate_key /etc/nginx/ssl/mailcom.rose.uni-heidelberg.de.key;
21+
22+
return 308 https://mailcom.rose.uni-heidelberg.de$request_uri;
23+
}
24+
25+
# Canonical HTTPS vhost: proxy to app
26+
server {
27+
listen 443 ssl;
28+
listen [::]:443 ssl;
29+
http2 on;
30+
server_name mailcom.rose.uni-heidelberg.de;
1731

1832
ssl_certificate /etc/nginx/ssl/mailcom.rose.uni-heidelberg.de.crt;
1933
ssl_certificate_key /etc/nginx/ssl/mailcom.rose.uni-heidelberg.de.key;
@@ -22,15 +36,14 @@ server {
2236
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256';
2337
ssl_prefer_server_ciphers on;
2438

25-
# If someone sends HTTP to 443, redirect to HTTPS
26-
error_page 497 =301 https://$host$request_uri;
27-
2839
location / {
2940
proxy_pass http://app_server;
3041
proxy_set_header Host $host;
42+
proxy_set_header X-Forwarded-Host $host;
43+
proxy_set_header X-Forwarded-Proto $scheme;
44+
proxy_set_header X-Forwarded-Port $server_port;
3145
proxy_set_header X-Real-IP $remote_addr;
3246
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
33-
proxy_set_header X-Forwarded-Proto $scheme;
3447
proxy_http_version 1.1;
3548
}
3649
}

0 commit comments

Comments
 (0)