GithubHelp home page GithubHelp logo

i40west / netlify-cms-cloudflare-pages Goto Github PK

View Code? Open in Web Editor NEW
86.0 3.0 20.0 23 KB

Oauth API to run Decap CMS (formerly Netlify CMS) on Cloudflare Pages

License: BSD 3-Clause "New" or "Revised" License

JavaScript 10.74% HTML 1.24% CSS 88.02%
cloudflare-pages cms jamstack cloudflare-workers netlify-cms static-site decap-cms

netlify-cms-cloudflare-pages's Introduction

netlify-cms-cloudflare-pages

Decap CMS (formerly Netlify CMS) needs to authenticate to Github with OAuth. Github needs a server to talk to during the authentication process. If you’re hosting at Netlify, they take care of that. If not, you’re on your own, and the documentation is... imperfect. 😂

If you’re deploying to Cloudflare Pages this may be the code you’re looking for. It provides API endpoints for Github to talk to, running on Cloudflare Functions. Functions are kind of like Cloudflare Workers, but they run right from your Pages site.

Credits

This is based on d3v1an7/netlify-cms-oauth-cloudflare adapted for Cloudflare Functions.

Installation

1. Create OAuth application at Github

Go to Settings -> Developer Settings and choose OAuth Apps. Create a new OAuth App. Name it anything you like. Homepage URL should be set to your site’s URL. Authorization callback URL is the important part; it, too, can be set to your homepage URL (like https://example.com). Other guides say to set this to the callback API endpoint, but the documented requirement is that the callback URL be a subdirectory of this URL, and using the callback URL itself didn’t work for me.

Github will give you a Client ID, and you can generate a Client Secret at this time. You will need both.

2. Add Client ID and Secret to your Cloudflare project

In your Cloudflare Pages project, go to Settings -> Environment variables. Add two environment variables, GITHUB_CLIENT_ID set to the client ID from above, and GITHUB_CLIENT_SECRET set to the secret.

3. Add the files to your project

Take the functions directory from this repo and add it to your project at the top level. NOTE: This means the actual top-level of the project itself, not the top level of your output directory. So, if you’re using Hugo, functions goes at the top of the project next to content and layouts and archetypes and so forth, not inside the static or assets directory.

If you haven’t already installed the Decap CMS files, take the static/admin directory from this repo and add it to your static directory (for Hugo) or wherever you add files to be deployed as-is to your site. There are two files under admin, a stub HTML file that loads the CMS, and the CMS config file config.yml. You can change the name of the admin directory.

The config file included here is a starter file only; you need to set this up for your site, which is beyond the scope of these instructions. However, you must set site_domain and base_url in this config to the URL of your site (like https://example.com). Setting auth_endpoint here is optional because the default path works for the way this repo is set up.

4. Profit!

Publish your site and let Cloudflare build it. Go to /admin/ on your site, and you should see a Login with Github button, which should authenticate you to Github and launch the CMS.

netlify-cms-cloudflare-pages's People

Contributors

i40west avatar khrlzhfr avatar ramiro avatar subhendux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

netlify-cms-cloudflare-pages's Issues

This is pure gold

This repo / instructions are pure gold! I've been searching for a elegant, flat file / git ops CMS similar to Netlify CMS for deploying on Cloudflare Pages.

Do you believe it would be possible to have multiple editors / admins for the CMS.

Tks for sharing!

OAuth not presenting itself.

First off: Thank you for sharing this, as it is much needed.

Unfortunately, it doesn't seem to be working for me. When heading to Netlify CMS login at /admin/ seeing login options for email and password but no GitHub authorization button.

In fact, it seems to be redirecting to /admin/#/ rather than the Github authorization page.

Callback.js response not interpreted correctly by browser

The auth process appears to work up until the call back function is called. Its like the browser is treating the response from the function as string text instead of HTML. I tried updating the html to include the full html, head, body tags but that didn't have any effect. The response gets wrapped in a

 tag and rendered as plain text in the browser. I've tried in Chrome and Firefox. I'm sure I'm just missing something here but I've tried going though the setup several times now with same result.

image

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.