fullstack-lang / gongdoc

A gong stack for editing UML diagrams of gong code
MIT License
1 stars 0 forks source link

On Chrome and Safari (not Firefox), on mac (not windows), on 8080 (not 4200), Get on REST API does not work (is mangled) #134

Closed thomaspeugeot closed 1 year ago

thomaspeugeot commented 1 year ago

Http GET get http://localhost:8080/api/github.com/fullstack-lang/gongdoc/go/v1/commitfrombacknb

and the url becomes http://localhost:8080/

Object { headers: {…}, status: 200, statusText: "OK", url: "http://localhost:8080/", ok: false, name: "HttpErrorResponse", message: "Http failure during parsing for http://localhost:8080/", error: {…} }
​
commitnbfromback.service.ts:63:20
thomaspeugeot commented 1 year ago

The only difference between this get and the other get is that this one requests a number, not a json .

Let's try with a json. Does not change the problem.

thomaspeugeot commented 1 year ago

Another solution is to start from scratch the service. Follow what angular says.

https://angular.io/guide/http


@Injectable({
    providedIn: 'root'
})
export class CommitNbFromBackService {

    configUrl = 'api/github.com/fullstack-lang/gongdoc/go/v1/commitfrombacknb'

    getCommitNbFromBack(): Observable<number> {
        return this.http.get<number>(this.configUrl);
    }

    constructor(
        private http: HttpClient
    ) {
    }
}

same error

thomaspeugeot commented 1 year ago

since this is a problem with the runtime vs debug version, I wonder wether it is related to he compiler options.

started a ng project from scratch. does not work.

thomaspeugeot commented 1 year ago

I have to reproduce the bug with a very small project

thomaspeugeot commented 1 year ago

CORS issue ?

https://stackoverflow.com/questions/54705306/angular-http-request-return-null-in-chrome-but-works-in-firefox

thomaspeugeot commented 1 year ago

Maybe this is because , both the tree component and the classdiagram component call the service simultaneously.

thomaspeugeot commented 1 year ago

somethng, the same error occurs in debug mode on chrome (on 4200).

CORS error.

Request URL: http://localhost:8080/api/github.com/fullstack-lang/gongdoc/go/v1/commitfrombacknb
Request Method: GET
Status Code: 301 Moved Permanently
Referrer Policy: strict-origin-when-cross-origin
Content-Length: 36
Content-Type: text/html; charset=utf-8
Date: Mon, 13 Feb 2023 07:20:11 GMT
Location: /

The Status Code is from the go handling of static path.

    r.NoRoute(func(c *gin.Context) {
        fmt.Println(c.Request.URL.Path, "doesn't exists, redirect on /")
        c.Redirect(http.StatusMovedPermanently, "/")
        c.Abort()
    })

One should debug the backend at this stage.

thomaspeugeot commented 1 year ago

The is also this answer

https://stackoverflow.com/questions/30656293/angular-options-http-preflight-on-same-domain

You can't use localhost. I had to create an entry in my host file to associate 127.0.0.1 to an arbitrary name like mackbook. Then it should work for you.

thomaspeugeot commented 1 year ago

all right, let's test some hypotheses.

if the problem is a CORS, then the problem occurs dring the PRE FLIGHT XML Http Request with "/". and it could be intercepted by the go debugger.

this is not the case, the call is not intercepted. the 301 is still present. "has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."

thomaspeugeot commented 1 year ago

Using chrome with security disabled does not work either

open -n -a "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --args -disable-web-security

thomaspeugeot commented 1 year ago

https://stackoverflow.com/questions/10883211/why-does-my-http-localhost-cors-origin-not-work

https://bugs.chromium.org/p/chromium/issues/detail?id=67743

IT WORKS !!

Screenshot 2023-02-21 at 01 12 47