Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes redirects #14

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
]
}
Loading