Skip to content

Commit

Permalink
Merge pull request #14 from PotLock/fix/redirects
Browse files Browse the repository at this point in the history
Fixes redirects
  • Loading branch information
elliotBraem authored Jan 16, 2025
2 parents acbe148 + 90193f3 commit 964da3f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 44 deletions.
53 changes: 13 additions & 40 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import dotenv from "dotenv";
import path from "path";
import { Elysia } from "elysia";
import { cors } from "@elysiajs/cors";
import { swagger } from "@elysiajs/swagger";
import { staticPlugin } from "@elysiajs/static";
import { swagger } from "@elysiajs/swagger";
import { ServerWebSocket } from "bun";
import dotenv from "dotenv";
import { Elysia } from "elysia";
import path from "path";
import { DistributionService } from "services/distribution/distribution.service";
import configService, { validateEnv } from "./config/config";
import { db } from "./services/db";
import RssPlugin from "./external/rss";
import { db } from "./services/db";
import { SubmissionService } from "./services/submissions/submission.service";
import { TwitterService } from "./services/twitter/client";
import {
Expand All @@ -17,9 +18,11 @@ import {
startSpinner,
succeedSpinner,
} from "./utils/logger";
import { ServerWebSocket } from "bun";

const PORT = Number(process.env.PORT) || 3000;
const FRONTEND_DIST_PATH =
process.env.FRONTEND_DIST_PATH ||
path.join(process.cwd(), "../frontend/dist");

// Store active WebSocket connections
const activeConnections = new Set();
Expand Down Expand Up @@ -211,45 +214,15 @@ export async function main() {

return { processed };
})
// Serve static files in production
// This was the most annoying thing to set up and debug. Serves our frontend and handles routing. alwaysStatic is essential.
.use(
staticPlugin({
assets:
process.env.FRONTEND_DIST_PATH ||
path.join(process.cwd(), "../frontend/dist"),
assets: FRONTEND_DIST_PATH,
prefix: "/",
indexHTML: true, // Enable SPA routing
alwaysStatic: true,
}),
)
.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);
return new Response(
JSON.stringify({
error:
error instanceof Error ? error.message : "Internal server error",
}),
{
status:
error instanceof Error && error.message === "Not found"
? 404
: 500,
headers: { "Content-Type": "application/json" },
},
);
})
.get("/*", () => Bun.file(`${FRONTEND_DIST_PATH}/index.html`))
.listen(PORT);

succeedSpinner("server", `Server running on port ${PORT}`);
Expand Down
Binary file modified bun.lockb
Binary file not shown.
7 changes: 3 additions & 4 deletions frontend/vercel.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"redirects": [
"rewrites": [
{
"source": "/:path*",
"destination": "https://curatedotfun.fly.dev/:path*",
"permanent": true
"source": "/(.*)",
"destination": "https://curatedotfun.fly.dev/$1"
}
]
}

0 comments on commit 964da3f

Please sign in to comment.