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

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

Open
pisacode opened this issue Jul 24, 2021 · 1 comment
Open

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

pisacode opened this issue Jul 24, 2021 · 1 comment

Comments

@pisacode
Copy link

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?

@rglover
Copy link
Contributor

rglover commented Aug 2, 2021

Hi @pisacode, you should be able to update the list of allowed domains in your settings-production.json file under the URLs block (see an example here: https://github.com/cheatcode/nodejs-server-boilerplate/blob/master/settings-development.json#L20), or, by modifying the CORS middleware directly in /middleware/cors.js here: https://github.com/cheatcode/nodejs-server-boilerplate/blob/master/middleware/cors.js#L4.

Once the URL is added, the CORS policy should kick in and allow you to do cross-domain requests.

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