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

Not working with nested plugin app #23

Open
houssemFat opened this issue Jan 7, 2024 · 1 comment
Open

Not working with nested plugin app #23

houssemFat opened this issue Jan 7, 2024 · 1 comment

Comments

@houssemFat
Copy link

Hi , thank you for all the effort behind elysia and elysia-static.

Description

I'm trying to use a SSR plugin and i need theelysia-static plugin only on production. So i will check if i'm in prod or dev mode and i will use a custom plugin that will include elysia-static in the Elysia app (nested app for plugin). When we use the plugin in the main Elysia instance (the instance that acts as server) , the plugin works fine , but when we use it with a nested Elysia app (a plugin Elysia app), the plugin don't work as expected (I get 404).

Below my folder structure.

image

Usage with the main Elysia instance : OK

Works fine when using the plugin with main Elysia instance. The http://localhost:2000/assets/index-BRPLnx8F.js url returns the file.

main.js

let elysia = new Elysia(); 

...
elysia = elysia
            .use(staticPlugin({
                prefix: "/",
                assets: path.join(process.cwd(), 'src', 'client', 'dist', 'client')
            }))
            .use(SSRPlugin);
    
elysia.listen(2000)

Usage with Nested plugin : NOK

the http://localhost:2000/assets/index-BRPLnx8F.js returns NOT_FOUND

SSRPlugin.js

export const SSRPlugin = async () => {
    const app = new Elysia({
        name: 'vite',
        seed: {}
    })
    app
        // not working with nested
        .use(staticPlugin({
            prefix: "/",
            // assets: 'src/client/dist/client'
            assets: path.join(process.cwd(), 'src', 'client', 'dist', 'client')
        }))
     ..... 
    return app
}

main.js

let elysia = new Elysia(); 
... 
elysia = elysia
            .use(SSRPlugin);
elysia.listen(2000)

Info

  "dependencies": {
    "@bogeychan/elysia-logger": "^0.0.15",
    "@elysiajs/html": "^0.8.0",
    "@elysiajs/static": "^0.8.0",
    "@elysiajs/server-timing": "^0.8.0",
    "elysia-compression": "^0.0.7",
    "elysia": "^0.8.8",
    .....
  }
@adicco
Copy link

adicco commented Jan 12, 2024

I can confirm the same thing. Wrapping the static plugin in a separate Elysia app, like this:

export const serveStaticFiles = new Elysia({ name: '~/lib/serveStatic' }).use(
  staticPlugin(
    NODE_ENV === 'development'
      ? {
          headers: {
            'Cache-Control':
              'no-store, no-cache, must-revalidate, proxy-revalidate',
            Expires: '0',
            'Surrogate-Control': 'no-store',
            Pragma: 'no-cache',
          },
        }
      : {},
  ),
);

raises the following TypeScript error:

lib/serveStatic.ts:6:3 - error TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type 'Promise<Elysia<"", { request: {}; store: {}; derive: {}; resolve: {}; }, { type: {}; error: {}; }, {}, {
}, {}, false>>' is not assignable to parameter of type 'Promise<{ default: Elysia<any, any, any, any, any, any, any>; }>'.
      Property 'default' is missing in type 'Elysia<"", { request: {}; store: {}; derive: {}; resolve: {}; }, { type: {}; erro
r: {}; }, {}, {}, {}, false>' but required in type '{ default: Elysia<any, any, any, any, any, any, any>; }'.

  6   staticPlugin(
      ~~~~~~~~~~~~~
  7     NODE_ENV === 'development'
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... 
 17       : {},
    ~~~~~~~~~~~
 18   ),
    ~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants