Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotBraem committed Jan 16, 2025
1 parent 5f6d5e8 commit b78df2e
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 23 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ WORKDIR /app
# Copy backend package files
COPY package.json ./
COPY backend/package.json ./backend/
COPY backend/drizzle.config.ts ./backend/

# Install backend dependencies
RUN cd backend && bun install
Expand Down Expand Up @@ -57,11 +58,14 @@ COPY --from=backend-builder --chown=bun:bun /app/package.json ./
COPY --chown=bun:bun curate.config.json ./

COPY --from=frontend-builder --chown=bun:bun /app/frontend/dist ./frontend/dist
COPY --from=backend-builder --chown=bun:bun /app/backend/dist ./backend/dist
COPY --from=backend-builder --chown=bun:bun /app/backend ./backend

RUN cd backend && bun install

# Set environment variables
ENV DATABASE_URL="file:/litefs/db"
ENV NODE_ENV="production"
ENV FRONTEND_DIST_PATH="/app/frontend/dist"

# Expose the port
EXPOSE 3000
Expand Down
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"dependencies": {
"@elysiajs/cors": "^1.2.0",
"@elysiajs/static": "^1.2.0",
"@elysiajs/swagger": "^1.2.0",
"@libsql/client": "^0.14.0",
"@types/cors": "^2.8.17",
Expand Down
31 changes: 14 additions & 17 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from "path";
import { Elysia } from "elysia";
import { cors } from "@elysiajs/cors";
import { swagger } from "@elysiajs/swagger";
import { staticPlugin } from "@elysiajs/static";
import { DistributionService } from "services/distribution/distribution.service";
import configService, { validateEnv } from "./config/config";
import { db } from "./services/db";
Expand Down Expand Up @@ -210,23 +211,19 @@ export async function main() {

return { processed };
})
// Static file serving in production
.get("/*", async ({ request }) => {
if (process.env.NODE_ENV === "production") {
const url = new URL(request.url);
const filePath = url.pathname === "/" ? "/index.html" : url.pathname;
const file = Bun.file(
path.join(__dirname, "../../frontend/dist", filePath),
);
if (await file.exists()) {
return new Response(file);
}
// Fallback to index.html for client-side routing
return new Response(
Bun.file(path.join(__dirname, "../../frontend/dist/index.html")),
);
}
throw new Error("Not found");
// Serve static files in production
.use(staticPlugin({
assets: process.env.FRONTEND_DIST_PATH || path.join(process.cwd(), "../frontend/dist"),
prefix: "/",
indexHTML: true // Enable SPA routing
}))
.get("/debug/env", () => {
return {
cwd: process.cwd(),
frontendPath: process.env.FRONTEND_DIST_PATH || path.join(process.cwd(), "../frontend/dist"),
resolvedPath: path.resolve(process.env.FRONTEND_DIST_PATH || path.join(process.cwd(), "../frontend/dist")),
env: process.env.NODE_ENV
};
})
.onError(({ error }) => {
logger.error("Request error:", error);
Expand Down
6 changes: 2 additions & 4 deletions backend/src/services/twitter/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ export class TwitterService {
private async setCookiesFromArray(cookies: TwitterCookie[]) {
const cookieStrings = cookies.map(
(cookie) =>
`${cookie.name}=${cookie.value}; Domain=${cookie.domain}; Path=${cookie.path}; ${
cookie.secure ? "Secure" : ""
}; ${cookie.httpOnly ? "HttpOnly" : ""}; SameSite=${
cookie.sameSite || "Lax"
`${cookie.name}=${cookie.value}; Domain=${cookie.domain}; Path=${cookie.path}; ${cookie.secure ? "Secure" : ""
}; ${cookie.httpOnly ? "HttpOnly" : ""}; SameSite=${cookie.sameSite || "Lax"
}`,
);
await this.client.setCookies(cookieStrings);
Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 0 additions & 1 deletion fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ primary_region = 'den'
memory = '1gb'
cpu_kind = 'shared'
cpus = 1

1 change: 1 addition & 0 deletions litefs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ proxy:
# the last command to be long-running (e.g. an application server). When the
# last command exits, LiteFS is shut down.
exec:
- cmd: "bun run db:push"
- cmd: "bun run start"

# The lease section specifies how the cluster will be managed. We're using the
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev": "bunx turbo run dev",
"build": "bunx turbo run build",
"start": "NODE_ENV=production cd backend && bun run dist/index.js",
"db:push": "cd backend && bun run db:push",
"lint": "bunx turbo run lint",
"deploy:init": "fly launch && fly consul attach",
"deploy": "fly deploy",
Expand Down

0 comments on commit b78df2e

Please sign in to comment.