dotnize / chessu

Online multiplayer chess built with Next.js, Express, & socket.io
MIT License
75 stars 29 forks source link

Im aiming at adding a feature to the mono-repo. 🤞 #26

Open mworks-proj opened 6 months ago

mworks-proj commented 6 months ago

Locally, this works correctly but when deploying client/ to vercel w/ (Postgres db) and server/ types/ on aws nodejs w/ bitnami (different domain) i get cors error.

My goal is to ultimately deploy with evernode hotpocket after compiling the required "server" and directory files.

Some thoughts im having: our hosts allow access to user ports starting at :8080 + And peer ports at 22861 +

In the docs the server listens on :3001 and client on :3000

  1. Can we modify this for client or server in config?

  2. The db should reside on server or vercel?

  3. Suggestions on compiling?

I greatly appreciate your feedback. ♟️

dotnize commented 6 months ago

Hello. I haven't tried deploying this with different domains for the client and server, but it should probably work if you set the CORS_ORIGIN env variable on the server.

  1. For the client, you can use the -p flag to change the port (e.g. pnpm dev:client -p 8080 or pnpm start:client -p 8080) - Next.js CLI. But I think Vercel handles this automatically when deploying?

    For the server, you can add the PORT environment variable to change the server port.

    Here's the full list of environment variables you can use for the client and server (from CONTRIBUTING.md): client:

    NEXT_PUBLIC_API_URL=http://localhost:3001 # replace with backend URL

    server:

    CORS_ORIGIN=http://localhost:3000 # replace with frontend URL
    PORT=3001
    SESSION_SECRET=randomstring # replace for security
    
    # PostgreSQL connection info (required)
    PGHOST=db.example.com
    PGUSER=exampleuser
    PGPASSWORD=examplepassword
    PGDATABASE=chessu
  2. Ideally on the server, but it should work on Vercel Postgres or anywhere else as long as your Express/Node server can connect to it.

  3. I used to deploy the client on Vercel, and the server/db on Railway.

    For the client, I deployed the whole repo with these settings: image Make sure to set the Root Directory to client and check "Include source files outside ..." (edit: I'm not sure if the Install Command needs to be overridden. Try using their default option if it doesn't work.)

    For the server, I also deployed the whole repo (but only the root package.json, server/, and types/ folders are needed). Then on the root directory of the repo/project, pnpm install:server to only install server dependencies, pnpm build:server, then pnpm start:server.

    You can check the root package.json for the full list of scripts/commands to help you deploy each environment.

Hope that helps :)