0

As a junior developer i'm facing a problem with koa-static.

I have two graphiQL playground on /private and /admin. The documentation was koa-static serve() from an index.html file (same doc for both).

app.use(serve(path.resolve("./static")));
...
const privateApollo = new ApolloServer(privateApolloConfig as Config);
privateApollo.applyMiddleware({ app, path: "/graphql/private", cors: corsConfig });

const adminApollo = new ApolloServer(adminApolloConfig as Config);
adminApollo.applyMiddleware({ app, path: "/graphql/admin", cors: corsConfig });

I had to create a third apolloServer with a graphiQL playground on /public. Everything is working but i now want to differentiate the documentation for each playground.

I've discovered koa-mount which seems to do exactly that but i cant make it work. I've tried this:

app.use(mount("/graphql/public", serve(path.resolve("./static/graphql/public"))));
app.use(mount("/graphql/admin", serve(path.resolve("./static/graphql/admin"))));
app.use(mount("/graphql/private", serve(path.resolve("./static/graphql/private"))));

Inspiration here : https://stackoverflow.com/a/66377342

Tried multiple variation of the code seen in the stackoverflow link.

app.use(mount("/graphql/public", serve(path.join(__dirname, "./static/graphql/public")))); app.use(mount("/graphql/public", serve("../static/graphql/public"))); app.use(mount("/graphql/public", serve(path.resolve("./static/graphql/public")))); ...

Yukie_ch
  • 1
  • 1
  • For people seeing this topic for having the same problem, i can confirm that app.use(mount("/graphql/public", serve(path.resolve("./static/graphql/public")))); Was the right syntax. My problem was cause by the graphiQL playground having a "http://localhost:4000/graphql/public" next to history that wasnt changing when i swapped the URL. – Yukie_ch Jul 05 '23 at 14:17

0 Answers0