elysia icon indicating copy to clipboard operation
elysia copied to clipboard

Support for Remix

Open Marcisbee opened this issue 2 years ago • 23 comments

Any plans to support Remix with custom server adapter similar to @remix-run/express?

Marcisbee avatar Jan 13 '23 07:01 Marcisbee

Sure, I love Remix.

Added to roadmap

SaltyAom avatar Jan 17 '23 06:01 SaltyAom

Blocking on: https://github.com/oven-sh/bun/issues/1864

SaltyAom avatar Jan 22 '23 10:01 SaltyAom

Is this unblocked now via this PR?

  • https://github.com/oven-sh/bun/pull/2019

Marcisbee avatar Feb 16 '23 17:02 Marcisbee

Likely yes, will continue working on an adapter after the PR landed on stable (likely Bun 0.5.7)

SaltyAom avatar Feb 23 '23 14:02 SaltyAom

any update? :)

tobimori avatar Sep 13 '23 07:09 tobimori

any update?

rashidtvmr avatar Sep 15 '23 05:09 rashidtvmr

Apparently elysia + remix is already supported. You just need to make some tweeks https://github.com/wladiston/elysia-remix

wladpaiva avatar Sep 29 '23 20:09 wladpaiva

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

TaQuanMinhLong avatar Dec 31 '23 16:12 TaQuanMinhLong

Any update for official remix support?

sabinpuiu avatar Feb 26 '24 15:02 sabinpuiu

Any update for official remix support 🥹

Danieljs-codes avatar Mar 16 '24 18:03 Danieljs-codes

+1

sigmachirality avatar Mar 26 '24 16:03 sigmachirality

+1

Danieljs-codes avatar Mar 30 '24 16:03 Danieljs-codes

+1

ZorikovPasha avatar Apr 07 '24 08:04 ZorikovPasha

Is there any current path here that works now that remix uses vite?

stephen776 avatar May 31 '24 02:05 stephen776

do we have any example use of elysia and remix as monorepo?

broisnischal avatar Jun 26 '24 16:06 broisnischal

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!

dy0gu avatar Jun 30 '24 21:06 dy0gu

https://github.com/user-attachments/assets/725a4a85-d883-4a62-af81-9335482d9d2c

I work on it

SOON...

kravetsone avatar Jul 20 '24 13:07 kravetsone

I publish [email protected]!

Currently, sending files from public dir in development mode does not work

Waiting for your stars and issues ✨

kravetsone avatar Jul 20 '24 20:07 kravetsone

@Marcisbee Can you share the feedback and if everything is fine close the issue?

kravetsone avatar Jul 25 '24 12:07 kravetsone

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.

dy0gu avatar Jul 27 '24 13:07 dy0gu

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.

But public folder works today Do u have issues with it?

kravetsone avatar Jul 27 '24 17:07 kravetsone

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.

But public folder works today Do u have issues with it?

Ahh really i forgot to mention it here

kravetsone avatar Jul 27 '24 17:07 kravetsone

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 dev

In 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 start

In 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!

dy0gu avatar Jul 27 '24 18:07 dy0gu

Closing as supported as 3rd party http://github.com/kravetsone/elysia-remix

SaltyAom avatar Aug 30 '24 16:08 SaltyAom