Hello world, are there best practices for serving ...
# orm-help
l
Hello world, are there best practices for serving the frontend using graphql-yoga's express instance? I tried adding
server.express.use(nuxt.render)
but the graphql requests fall-through to Nuxt... is there a way to make graphql-yoga's endpoints call
res.end()
to prevent this? Thanks!
b
I haven't used nuxt, but don't you need to add the route, to avoid the handler being called on every request? eg.
server.express.use('/*', nuxt.render)
or
server.express.get
, if nuxt is only handling GET requests
l
if I place the
server.express.use
before
server.start
Nuxt serves a 404 on the /playground route, wether I use a route or not
If I place it after
server.start
, the prisma endpoints don't terminate the response and the request falls through to nuxt, which spits out a 404 (but the response in the browser is ok)
in apollo-server I could do this to prevent that:
Copy code
app.get(PLAYGROUND_ENDPOINT, expressPlayground({
      endpoint: GRAPHQL_ENDPOINT,
      subscriptionEndpoint: SUBSCRIPTIONS_ENDPOINT,
    }), (req, res) => res.end());
It works with a RegExp on req.path like so:
Copy code
server.express.use((req, res, next) => {
  if (req.path.match(/^\/(?!graphql|subscriptions|playground).*$/)) {
    nuxt.render(req, res, next);
  } else next();
});