elysia
elysia copied to clipboard
Support for Remix
Sure, I love Remix.
Added to roadmap
Blocking on: https://github.com/oven-sh/bun/issues/1864
Is this unblocked now via this PR?
- https://github.com/oven-sh/bun/pull/2019
Likely yes, will continue working on an adapter after the PR landed on stable (likely Bun 0.5.7)
any update? :)
any update?
Apparently elysia + remix is already supported. You just need to make some tweeks https://github.com/wladiston/elysia-remix
I did also manage to make it work, though only with production mode
// plugins/remix.ts
import type { ServerBuild } from "@remix-run/node";
import { createRequestHandler } from "@remix-run/node";
import { join, parse } from "path";
import { Elysia } from "elysia";
export type RemixPlugin<T extends ServerBuild = any> = (
serverBuild: T,
publicDir?: string
) => Elysia;
export const remix: RemixPlugin = (serverBuild, publicDir = join(process.cwd(), "public")) =>
new Elysia().all("*", async function ({ request, store, path, set }) {
if (request.method === "GET" && parse(path).ext) {
const filepath = join(publicDir, path);
const file = Bun.file(filepath);
const fileExist = await file.exists();
if (!fileExist) {
set.status = 404;
return { error: "Requested resource does not exist" };
}
set.headers["Cache-Control"] = "public,max-age=31536000,immutable";
return file;
}
/**
* This only works for production build
*
* For development use remix dev instead
*/
const handleRequest = createRequestHandler(serverBuild, "production");
return await handleRequest(request, store);
});
// server.ts
import { remix, logger } from "./plugins";
import { Elysia } from "elysia";
import * as build from "./build/index";
const port = process.env.PORT;
const app = new Elysia()
.state("appLoadContext", "test")
.use(logger())
.use(remix(build))
.listen(port ? Number(port) : 3000);
console.log(`Server is running at http://${app.server?.hostname}:${app.server?.port}`);
// Axios accept-encoding header should be set to gzip to work
...
headers: {
common: {
"Accept-Encoding": "gzip",
},
},
...
I'n not sure about this but after few clicks to test the router link, i feel that running original remix with bun is still somehow smoother than running remix by elysia 😂 It could be my implementation broke somewhere
Any update for official remix support?
Any update for official remix support 🥹
+1
+1
+1
Is there any current path here that works now that remix uses vite?
do we have any example use of elysia and remix as monorepo?
Can confirm, @TaQuanMinhLong's solution worked in production only.
It would be great to have official Remix support, elysia is looking amazing and I have already replaced my backend servers.
I'm just missing it on the frontend, for that sweet consistency!
https://github.com/user-attachments/assets/725a4a85-d883-4a62-af81-9335482d9d2c
I work on it
SOON...
I publish [email protected]!
Currently, sending files from public dir in development mode does not work
Waiting for your stars and issues ✨
@Marcisbee Can you share the feedback and if everything is fine close the issue?
Hey @kravetsone, I tried out your package and it seems pretty stable.
I left a Issue + PR to fix some of the problems in the example you give but other than that it seems great!
However, I think a working public directory in development is essential and we should make it a priority to fix that before closing this issue. I'd like to help but have no idea where to start so I guess I'll open another Issue on your repo about it and we'll go from there.
Hey @kravetsone, I tried out your package and it seems pretty stable.
I left a Issue + PR to fix some of the problems in the example you give but other than that it seems great!
However, I think a working
publicdirectory in development is essential and we should make it a priority to fix that before closing this issue. I'd like to help but have no idea where to start so I guess I'll open another Issue on your repo about it and we'll go from there.
But public folder works today
Do u have issues with it?
Hey @kravetsone, I tried out your package and it seems pretty stable.
I left a Issue + PR to fix some of the problems in the example you give but other than that it seems great!
However, I think a working
publicdirectory in development is essential and we should make it a priority to fix that before closing this issue. I'd like to help but have no idea where to start so I guess I'll open another Issue on your repo about it and we'll go from there.But
publicfolder works today Do u have issues with it?
Ahh really i forgot to mention it here
That's weird, I tried it today with the lastest version of Bun, Elysia itself and your package. I got the exact opposite of that behavior.
I created a minimal repository so you can see if you're able to reproduce the issue.
This is what happens (quoted from the README.md inside that repository):
Tested with Bun version 1.1.21
- Install dependencies with Bun
bun install
- Run in development mode:
bun run devIn this mode, all pages work normaly but files in the public folder are not being served.
- Run in production mode:
bun run build && bun run startIn this mode, all files in the public folder are being served but every page returns "NOT_FOUND"
Side note: I tried both with and without the app folder inside src, changing the corresponding appDirectory in the Remix vite.config.ts plugin config.
EDIT: I'm opening an issue related to this in your package repository so we don't spam this discussion for others!
Closing as supported as 3rd party http://github.com/kravetsone/elysia-remix