aidenhuynh / Epic_CSA

MIT License
0 stars 0 forks source link

Aiden Huynh, Period 1 - Debugging Event #6

Open aidenhuynh opened 9 months ago

aidenhuynh commented 9 months ago

How to Run with Debugger

Frontend

  1. Run locally using bundler, use whatever port bundle exec jekyll serve -P 4001

  2. Open up post/markdown page locally Screen Shot 2024-03-05 at 9 18 41 AM

  3. Open inspect and navigate to js code Screen Shot 2024-03-05 at 9 19 59 AM

  4. Add breakpoints by clicking on the line numbers on the left. Screen Shot 2024-03-05 at 9 19 45 AM

  5. When running code, press the arrow to step through each breakpoint. In our case, the code will be run when attempting to login. Screen Shot 2024-03-05 at 10 13 50 AM

Backend

  1. Navigate to Main.java
  2. In VSCode, press on the arrow next to the run button and click "Debug Java" Screen Shot 2024-03-05 at 9 43 22 AM

Demonstration on teacher_portfolio

First, we run our frontend locally with bundle exec jekyll serve -P 4001 and navigate to http://localhost:4001/teacher_portfolio/java/login (You can choose any port, but preferably not 4000 to see a CORS error later)

Then, inspect element and find the "login" js code in Sources

Setting three breakpoints on the .fetch, .then, and .catch allows us to see possible points of error from our frontend. Screen Shot 2024-03-05 at 9 19 45 AM

The following errors occur in different cases when trying to sign in:

  1. ERR_CONNECTION_REFUSED occurs from not running the backend, and is fixed by doing so Screen Shot 2024-03-05 at 9 23 41 AM

  2. This CORS error occurs from not allowing the correct origins on MvcConfig.java Screen Shot 2024-03-05 at 9 24 04 AM

This error is fixed by making sure the origin is allowed, and in this case, we had to change the port to match our localhost.

@Override
    public void addCorsMappings(@NonNull CorsRegistry registry) {
        registry.addMapping("/**").allowedOrigins("https://nighthawkcoders.github.io", "http://localhost:4001"); // Changed port to 4001 from 4000
    }
  1. The 401 error occurs from an authorization issue, which in this case was from incorrect login credentials Screen Shot 2024-03-05 at 9 26 41 AM

This is fixed by making sure to use the correct login information from Person.java, as we testing with a random password, instead of the actual password initialized within the file.

Successful Run

The expected outcome of properly avoiding all of these errors is being redirected to the data page (http://localhost:4001/teacher_portfolio/java/data). Yay!

Screen Shot 2024-03-05 at 9 27 48 AM

Demonstration on Team Project

I will be running our website's dashboard page for the frontend, and showing the backend interaction for fetching user information based on the inputted UID.

Screenshot of breakpoints

I have set breakpoints on the main .fetch, two of the .then's, and a .catch

Screen Shot 2024-03-05 at 10 34 16 AM

Catch output for funsies

I forgot to change the allowed origins so I got a CORS error when stepping through to the following .catch

.catch(error => {
            console.error('There was a problem with the fetch operation:', error);
});

Screen Shot 2024-03-05 at 1 51 50 PM

After editing the MvcConfig.java and SecurityConfig.java files to allow the port I was using, the issue was fixed.

Screenshot of data output

Data is returned from the fetch in the following code block:

.then(data => {
            console.log(JSON.stringify(data)); // Log the data
            populateAssignmentContainer(data); // Show the data on the frontend
})

Console output Screen Shot 2024-03-05 at 1 56 13 PM

Frontend update with data Screen Shot 2024-03-05 at 1 57 09 PM