fix: Use images

This commit is contained in:
Wanjohi
2025-06-13 13:57:43 +03:00
parent 88f499ba5e
commit 9827100d19
8 changed files with 109 additions and 5 deletions

22
infra/cdn.ts Normal file
View File

@@ -0,0 +1,22 @@
import { domain } from "./dns";
import { storage } from "./storage";
export const cdn = new sst.aws.Router("CDNRouter", {
routes: {
"/public": {
bucket: storage,
rewrite: {
regex: "^/public/([a-zA-Z0-9_-]+)$",
to: "/images/$1"
},
},
},
domain: {
name: "cdn." + domain,
dns: sst.cloudflare.dns()
}
});
export const outputs = {
cdn: cdn.url
}

View File

@@ -1 +1,5 @@
export const storage = new sst.aws.Bucket("Storage");
export const storage = new sst.aws.Bucket("Storage", {
access: "cloudfront"
});
export const zeroStorage = new sst.aws.Bucket("ZeroStorage");

View File

@@ -1,5 +1,6 @@
// This is the website part where people play and connect
import { api } from "./api";
import { cdn } from "./cdn";
import { auth } from "./auth";
import { zero } from "./zero";
import { domain } from "./dns";
@@ -16,6 +17,7 @@ new sst.aws.StaticSite("Web", {
},
environment: {
VITE_API_URL: api.url,
VITE_CDN_URL: cdn.url,
VITE_STAGE: $app.stage,
VITE_AUTH_URL: auth.url,
VITE_ZERO_URL: zero.url,

View File

@@ -2,8 +2,8 @@ import { auth } from "./auth";
import { domain } from "./dns";
import { readFileSync } from "fs";
import { cluster } from "./cluster";
import { storage } from "./storage";
import { postgres } from "./postgres";
import { zeroStorage } from "./storage";
const connectionString = $interpolate`postgresql://${postgres.username}:${postgres.password}@${postgres.host}:${postgres.port}/${postgres.database}`;
@@ -32,7 +32,7 @@ const zeroEnv = {
? {
}
: {
ZERO_LITESTREAM_BACKUP_URL: $interpolate`s3://${storage.name}/zero/0`,
ZERO_LITESTREAM_BACKUP_URL: $interpolate`s3://${zeroStorage.name}/zero/0`,
}),
};
@@ -46,7 +46,7 @@ const replicationManager = !$dev
capacity: "spot",
architecture: "arm64",
image: zeroEnv.ZERO_IMAGE_URL,
link: [storage, postgres],
link: [zeroStorage, postgres],
health: {
command: ["CMD-SHELL", "curl -f http://localhost:4849/ || exit 1"],
interval: "5 seconds",
@@ -123,7 +123,7 @@ const replicationManager = !$dev
export const zero = new sst.aws.Service("Zero", {
cluster,
image: zeroEnv.ZERO_IMAGE_URL,
link: [storage, postgres],
link: [zeroStorage, postgres],
architecture: "arm64",
cpu: "0.5 vCPU",
memory: "1 GB",