Skip to content

PhilDL/remix-ghost-stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Remix Ghost Stack

Warning!

This is still a work in progress, documentation is not ready For now if you want to try you should clone that repo and use pnpm i Some third-parties (Sendgrid, Stripe, Ghost) configuration documentation are not there yet!

Remix Ghost Stack Preview

Tech in the stack

Stack Features

  • Ghost CMS Pages, Posts, Authors, Tags
  • Stripe Subscriptions connects to your Ghost instance and the products you configured there.
  • Authentication Ready with Remix-Auth, Remix Auth OTP. Created to mimic the Ghost Membership login flow with magic link but also adding the convinience of a token Code.
  • Beautiful emails with React Emails, for Signup and Signin actions
  • Domain separated logic with domain functions

Ghost Features (some are currently in developement)

Built-in routes

  • Home: Pages, Posts, Authors, Tags + "load more posts..." action
  • Page // Post $slug + SSR Syntax Highlight with rehype prism
  • Author $slug + related posts
  • Tag $slug + related posts
  • All tags
  • All authors
  • Join + OTP Email magic link
  • Login + OTP Email magic link
  • Account + Subscribe redirect Stripe

SEO Metadata (Meta tags + OG + Twitter )

  • Home
  • Page // Post
  • Author
  • Tag

SEO JSONLD Schema

  • Home
  • Page // Post
  • Author
  • Tag

Development

  • Initial setup: If you just generated this project, this step has been done for you.

    pnpm run setup
  • Start dev server:

    pnpm run dev

This starts your app in development mode, rebuilding assets on file changes.

Relevant code:

This stack relies heavily on the @ts-ghost library providing full type-safe calls to the ghost Content and Admin APIs.

Unfortunately the API doesn't give us all the informations necessary to have a fully smooth headless experience. For example the tiers provided by the API don't give us access to the Stripe Product ID connected so we have to do a lookup by name. Which is not ideal but works for now.

Deployment

This Remix Stack comes with two GitHub Actions that handle automatically deploying your app to production and staging environments.

Prior to your first deployment, you'll need to do a few things:

  • Install Fly

  • Sign up and log in to Fly

    fly auth signup

    Note: If you have more than one Fly account, ensure that you are signed into the same account in the Fly CLI as you are in the browser. In your terminal, run fly auth whoami and ensure the email matches the Fly account signed into the browser.

  • Create two apps on Fly, one for staging and one for production:

    fly apps create remix-ghost-stack
    fly apps create remix-ghost-stack-staging

    Note: Make sure this name matches the app set in your fly.toml file. Otherwise, you will not be able to deploy.

    • Initialize Git.
    git init
  • Create a new GitHub Repository, and then add it as the remote for your project. Do not push your app yet!

    git remote add origin <ORIGIN_URL>
  • Add a FLY_API_TOKEN to your GitHub repo. To do this, go to your user settings on Fly and create a new token, then add it to your repo secrets with the name FLY_API_TOKEN.

  • Add a SESSION_SECRET to your fly app secrets, to do this you can run the following commands:

    fly secrets set SESSION_SECRET=$(openssl rand -hex 32) --app remix-ghost-stack
    fly secrets set SESSION_SECRET=$(openssl rand -hex 32) --app remix-ghost-stack-staging
    fly secrets set MAGIC_LINK_SECRET=$(openssl rand -hex 32) --app remix-ghost-stack
    fly secrets set MAGIC_LINK_SECRET=$(openssl rand -hex 32) --app remix-ghost-stack-staging
    fly secrets set APP_URL="https://remix-ghost-stack.fly.dev" --app remix-ghost-stack
    fly secrets set APP_URL="https://remix-ghost-stack-staging.fly.dev" --app remix-ghost-stack-staging

    If you don't have openssl installed, you can also use 1password to generate a random secret, just replace $(openssl rand -hex 32) with the generated secret.

Add secrets for third party services

  • From your Ghost CMS admin panel, add a new Ghost integration and copy paste the credentials:
fly secrets set GHOST_URL="https://remix-ghost-stack.digitalpress.blog" --app remix-ghost-stack
fly secrets set GHOST_CONTENT_API_KEY="your-content-api-key" --app remix-ghost-stack
fly secrets set GHOST_ADMIN_API_KEY="your-admin-api-key:your-admin-api-key" --app remix-ghost-stack

fly secrets set GHOST_URL="https://remix-ghost-stack.digitalpress.blog" --app remix-ghost-stack-staging
fly secrets set GHOST_CONTENT_API_KEY="your-content-api-key" --app remix-ghost-stack-staging
fly secrets set GHOST_ADMIN_API_KEY="your-admin-api-key:your-admin-api-key" --app remix-ghost-stack-staging
  • Your Stripe credentials:

    fly secrets set STRIPE_SECRET_KEY="sk_live_key" --app remix-ghost-stack
    fly secrets set STRIPE_PUBLIC_KEY="pk_live_key" --app remix-ghost-stack
    fly secrets set STRIPE_WEBHOOK_SIGNATURE="whsec_key" --app remix-ghost-stack
    
    fly secrets set STRIPE_SECRET_KEY="sk_test_key" --app remix-ghost-stack-staging
    fly secrets set STRIPE_PUBLIC_KEY="pk_test_key" --app remix-ghost-stack-staging
    fly secrets set STRIPE_WEBHOOK_SIGNATURE="whsec_test_key" --app remix-ghost-stack-staging

    Warning!

Here you should use the same Stripe account connected to your Ghost CMS !

You will have to generate a stripe webhook with these listeners:

Then copy paste your webhook secret set it via the fly CLI.

  • Your Sendgrid API Key

    fly secrets set SENDGRID_API_KEY="SG_sendgridkey" --app remix-ghost-stack
    fly secrets set SENDGRID_API_KEY="SG_sendgridkey" --app remix-ghost-stack-staging

Sendgrid is used to send the Login and Signup emails.

  • Create a persistent volume for the sqlite database for both your staging and production environments. Run the following:

    fly volumes create data --size 1 --app remix-ghost-stack
    fly volumes create data --size 1 --app remix-ghost-stack-staging

Now that everything is set up you can commit and push your changes to your repo. Every commit to your main branch will trigger a deployment to your production environment, and every commit to your dev branch will trigger a deployment to your staging environment.

Connecting to your database

The sqlite database lives at /data/sqlite.db in your deployed application. You can connect to the live database by running fly ssh console -C database-cli.

Getting Help with Deployment

If you run into any issues deploying to Fly, make sure you've followed all of the steps above and if you have, then post as many details about your deployment (including your app name) to the Fly support community. They're normally pretty responsive over there and hopefully can help resolve any of your deployment issues and questions.

GitHub Actions

We use GitHub Actions for continuous integration and deployment. Anything that gets into the main branch will be deployed to production after running tests/build/etc. Anything in the dev branch will be deployed to staging.

Testing

Playwright

Write doc

Vitest

For lower level tests of utilities and individual components, we use vitest. We have DOM-specific assertion helpers via @testing-library/jest-dom.

Type Checking

This project uses TypeScript. It's recommended to get TypeScript set up for your editor to get a really great in-editor experience with type checking and auto-complete. To run type checking across the whole project, run pnpm run typecheck.

Linting

This project uses ESLint for linting. That is configured in .eslintrc.js.

Formatting

We use Prettier for auto-formatting in this project. It's recommended to install an editor plugin (like the VSCode Prettier plugin) to get auto-formatting on save. There's also a pnpm run format script you can run to format all files in the project.

  • Tailwind prettier plugin
  • Sort inports

Aknowledgements

  • The theme was inspired by the amazing Ghost themes from Biron Themes
  • The stripe integration was heavily inspired by another amazing Remix template by dev-xo, Stripe Stack