Skip to content

How to host the client in the same server with backend. #18

Description

@pisacode

I have deploy both https://github.com/cheatcode/nodejs-server-boilerplate and https://github.com/cheatcode/nextjs-boilerplate on different servers but I am having problems with the authentication flow. The login method requires setting a cookie for authentication token but when server and client on cross domain, it is not able to set the cookie. Therefore I have put the client files under backend/client and redirected all traffic except api/graphql to client/build/index.html with the following code.

app.use(express.static('client/build'));

app.get('/api/graphql', (req, res) => {
  //What to do here to direct traffic to graphql server
});

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname + 'client/build/index.html'));
});

But I couldn't find a way to direct api/graphql to the graphql server.

is there a better approach?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions