Thinkmill / keystatic

First class CMS experience, TypeScript API, Markdown & YAML/JSON based, no DB
https://keystatic.com
MIT License
1.23k stars 79 forks source link

404 on Github login on Cloudflare #987

Closed NoelOConnell closed 4 months ago

NoelOConnell commented 8 months ago

The /keystatic page renders the "login with Github" button but clicking that gives a 404.

From the logs in Cloudflare

 "logs": [
    {
      "message": [
        "10:14:19 [WARN] [router] No API Route handler exists for the method \"GET\" for the route \"/api/keystatic/github/login\".\nFound handlers: \"ALL\", \"prerender\"\n"
      ],
      "level": "log",
      "timestamp": 1709806459296
    }
  ],

It seems that the handler is null https://github.com/withastro/astro/blob/e88eeb033749bd6bce8c00e712e207690ae9bf79/packages/astro/src/runtime/server/endpoint.ts#L26

It's a empty site with just a single index.astro page. This is what gets built and uploaded to Cloudflare. image

Here's the dependency list

"dependencies": {
    "@astrojs/cloudflare": "^9.0.2",
    "@astrojs/markdoc": "^0.9.0",
    "@astrojs/react": "^3.0.10",    
    "@keystatic/astro": "^5.0.0",
    "@keystatic/core": "^0.5.0",
    "@tailwindcss/forms": "^0.3.3",
    "@tailwindcss/typography": "^0.4.1",
    "@types/react": "^18.2.55",
    "@types/react-dom": "^18.2.19",
    "astro": "^4.4.10"
    ....
    }

I also forked Emma's Keystatic Cloudfare demo repo and updated packages and it shows the same issue.

emmatown commented 8 months ago

I just upgraded https://github.com/emmatown/keystatic-astro-cloudflare-workers-test and it seems to be working fine?

NoelOConnell commented 8 months ago

Thanks for the reply, I updated my fork to match your recent changes and still have the same issue.

https://keystatic-astro-cloudflare-workers-test-env.pages.dev/ https://github.com/NoelOConnell/keystatic-astro-cloudflare-workers-test

It deploys fine and the site works but I can't get pass the "login with Github" button on the /keystatic page so I can't go through the Github setup flow as per the docs. https://keystatic.com/docs/github-mode#connecting-with-git-hub

Is there any specific Cloudflare options/configuration required? Is there a way to setup the Github app another way to see if that is the part causing the issue?

NoelOConnell commented 8 months ago

Okay, I manage to get it to work.

I ran the project locally in github mode and I was able to go through the "login with Github" flow to create the Github app. Since it was setup locally is saves the localhost url for the callback links so I had to manually edit the newly create app in my Github account using the link https://github.com/settings/apps/{app name here} in my case that was {githubusername-keystatic}. I also had to add the new created KEYSTATIC_ variables to Cloudflare.

They /keystatic url now works and loads correctly but I can't make any changes, I just get [GraphQL] Resource not accessible by integration for any action. Update, I had to install the app on the repo since that part of the workflow failed due to the incorrect callback path for localhost.

So the issue is setting up the Github workflow and not the Cloudflare adapter.

jossmac commented 7 months ago

@NoelOConnell can this issue be closed?

emmatown commented 4 months ago

The GitHub App setup flow asks for the deployed URL so it can also add that URL as a callback URL as well but if that's missing then naturally you have to go into the GitHub App settings to add it yourself so everything here seems to working fine