GithubHelp home page GithubHelp logo

cp-web103-fall-2023-lab-9-soln's Introduction

Lab 9 Errata

Step 0: Prepare your project

Due to some recent change at Railway, this part is completely obsolete.

  • First, go into the client directory and npm install serve

  • Rename the current start script to dev. In the future, run npm run dev for local development

  • Add a new start script:

    "start": "serve build -s -n -L -p $PORT"
  • Your scripts section should now look like:

    "scripts": {
      "dev": "react-scripts start",
      "start": "serve build -s -n -L -p $PORT",
      "build": "react-scripts build",
      "test": "react-scripts test",
      "eject": "react-scripts eject"
    },

(Onthefly appears to have been converted from a create-react-app app. If using Vite from scratch, the start script should be: erve dist -s -n -L -p $PORT).

Step 1: Deploy the server

  • If you get an error message from Railway that says "Failed to Deploy! Invalid Service Name", it means your github repo's name is too long. Try shortening it! Max 27 characters, as far as I can tell.

Step 2: Deploy the client

  • Use this line for API_URL

    const API_URL = process.env.NODE_ENV === 'production' ? 'https://?????.up.railway.app' : 'http://localhost:3001'
    • Replace ????? with your server domain of course
  • Add the new API_URL variable to the useEffect() dependency list in App.js. This prevents warnings about missing variables in the dependency list:

    useEffect(() => {
      // ... getUser and fetchTrips function definitions ...
      getUser()
      fetchTrips()
    }, [API_URL]);

Step 4: Update server configuration

  • In server/server.js, refactor it to use a CLIENT_URL constant, and update the origin key for cors and the homepage redirect as follows:

    const CLIENT_URL = process.env.NODE_ENV === 'production' ? 'https://?????.up.railway.app' : 'http://localhost:3000'
    • Replace ????? with your client domain of course
    app.use(cors({
      origin: CLIENT_URL,
      methods: 'GET,POST,PUT,DELETE,PATCH',
      credentials: true
    }))
    app.get('/', (req, res) => {
      res.redirect(CLIENT_URL)
    })
  • In server/config/auth.js, update the successRedirect and failureRedirect values to simply '/'

cp-web103-fall-2023-lab-9-soln's People

Contributors

fredngo avatar

Watchers

 avatar

Forkers

kvv190001

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.