Code Monkey home page Code Monkey logo

jamstack-intro's Introduction

Introduction to the JAMstack

This is the code for a Frontend Masters workshop. In this workshop, we’ll learn what the JAMstack is, what it’s capable of, and how we can use it to build full-featured apps with less complexity and overhead.

Sections

Section 1: Create a Basic JAMstack Site

  • Create an index.html with a heading and a content area
  • Use npx serve to load the site during development
  • Create a styles.css with basic styles
  • Create a main.js that loads repos from GitHub
  • Add a link and a script element to index.html

Section 2: Deploy a JAMstack Site

  • Set up Netlify CLI yarn global add netlify-cli
  • Create a GitHub repository (use Hub) https://hub.github.com git create <repo-name>
  • Create a Netlify site connected to the GitHub repo netlify init
  • Push the code git add -A, git commit -m 'message', git push --set-upstream origin master
  • See the deploy netlify open
  • Push a change as a PR
    • Check out a new branch (git checkout -b feature-idea)
    • Make a change (add a body background color)
    • Add and commit the change (git commit -am 'feat: update background color')
    • Push the changes (git push origin feature-idea)
    • Open a pull request with Hub (git pull-request)
  • See the deploy as a preview
    • Show the live site vs. the deploy preview
  • Merge the pull request
  • See the deploy go live

Section 3: Serverless Functions

Before serverless functions, getting

  • What are serverless functions?
    • Talk about other providers
    • Use Netlify because it requires almost no setup/config
  • Create a "hello world" function
  • Use Netlify Dev to run it locally, Netlify Dev runs on port 8888
  • Learn about redirects to change the URL
  • Deploy and see it working live

Section 4: Process a Form Submission

  • Create an accessible form using React/CSS Modules
  • Use a reducer hook to manage form state
  • Handle idle, sending, and sent states
  • Create a serverless function
  • Get credentials from Mailgun (sandbox)
  • Use the serverless function to send email from the form

Section 5: Create a Password-Protected Dashboard

  • Add a home page and a dashboard page
  • Set up client-only routes in Gatsby
    • Use matchPath in gatsby-node.js
    • Create components to show at different sub-routes (e.g. /dashboard/login)
    • Add a redirect for Netlify
  • Deploy the site to Netlify
    • Required so we can activate Identity
  • Add authentication w/Netlify Dev, netlify dev runs on port 8888, so access the site through localhost:8888
    • yarn add react-netlify-identity-widget react-netlify-identity @reach/dialog @reach/tabs @reach/visually-hidden
    • Create a Layout component that wraps everything with the provider
    • Add the Identity modal to the dashboard page
    • Add a Profile component to show whether or not we’re logged in
    • Add navigation for the dashboard
    • Create a PrivateRoute component to bounce to the login screen if not logged in
    • Update Dashboard to use private routes
  • Deploy
  • Sign up for an account
  • Bounce to login screen when accessing protected routes while logged out

Section 6: Create a DB-Backed Todo App

  • Create a Fauna account (https://fauna.com)
  • Write a GraphQL schema (functions/utils/todos.gql)
  • Create a new Fauna DB (https://dashboard.fauna.com/db-new/)
  • Upload the GraphQL schema to Fauna
  • Explore the GraphQL Playground in Fauna
  • Create an API server key in the “security” tab
  • Add the server key to .env
  • Create a helper for serverless functions (functions/utils/send-query.js)
  • netlify dev runs on port 8888, so access the site through localhost:8888 (not 8000)
  • Load all todos
    • Create a serverless function /functions/get-all-todos.js
    • Write a hook to load todos
    • Create a Todo component to display todo items
  • Add the ability to create todos
    • Create a serverless function /functions/create-todo.js
    • Create a Form component
  • Add the ability to toggle todo completed state
    • Create a serverless function /functions/toggle-completed.js
    • Add a checkbox input to show completed state and handle toggling
  • Add the ability to delete todos
    • Create a serverless function /functions/delete-todo.js
    • Add a button to delete todos

Thanks

Huge thanks to David Khourshid and Ryan Florence for reviewing code and providing better patterns for using React Hooks. Thanks to Sarah Drasner for sharing notes and examples from her JAMstack workshop.

jamstack-intro's People

Contributors

1marc avatar jlengstorf 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

Watchers

 avatar  avatar  avatar  avatar

jamstack-intro's Issues

TypeError [ERR_INVALID_ARG_TYPE] on netlify dev

Don't know if this is the right place to leave a comment like this but got stuck here from a while. Kept on getting the error message

Request from ::1: GET /.netlify/functions/hello Response with status 500 in 5 ms. TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received null at validateString (internal/validators.js:118:11) at Object.resolve (path.js:980:7)

Whenever I tried the netlify dev command of the first serverless hello.js deploy, in video "Setup API URL" of section "Serverless contact form".
It appears you have to have an existing package.json file for this to work. This is most easily accomplished by running yarn init -y - or npm init in the current working directory (in this case /sections/contacts/). Hope it helps someone!

Setup API URL Issue.

when i go to http://localhost:8888/api/hello or the .netlify version, i'm getting this message:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received null
at validateString (internal/validators.js:117:11)
at Object.resolve (path.js:139:9)
at C:\Users\Jordan\AppData\Local\Yarn\Data\global\node_modules\netlify-cli\src\utils\serve-functions.js:163:21
at Layer.handle [as handle_request] (C:\Users\Jordan\AppData\Local\Yarn\Data\global\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\Jordan\AppData\Local\Yarn\Data\global\node_modules\express\lib\router\route.js:137:13)
at next (C:\Users\Jordan\AppData\Local\Yarn\Data\global\node_modules\express\lib\router\route.js:131:14)
at next (C:\Users\Jordan\AppData\Local\Yarn\Data\global\node_modules\express\lib\router\route.js:131:14)
at next (C:\Users\Jordan\AppData\Local\Yarn\Data\global\node_modules\express\lib\router\route.js:131:14)
at next (C:\Users\Jordan\AppData\Local\Yarn\Data\global\node_modules\express\lib\router\route.js:131:14)
at next (C:\Users\Jordan\AppData\Local\Yarn\Data\global\node_modules\express\lib\router\route.js:131:14)

I don't know why... Can you help me ?

How Are Errors Being Returned From Send Query Util

I understand that the Send Query util file was created to avoid replication of sending GraphQL requests to the server. However, I don't know how errors are being returned. It appears to only return result.data (after the promise is awaited obviously).

For example, when using the sendQuery you get back an object where you restructure the two properties data and errors. Where does errors come from?

  const { data, errors } = await sendQuery(LOAD_ALL_TODOS);

And for that matter where does data come from in terms of the object restructuring. I would have expected something like this.

  const data = await sendQuery(LOAD_ALL_TODOS);

Does the GraphQL endpoint return an object that has both the data and errors properties? So, the original code might look like this without restructuring?

  const res= await sendQuery(LOAD_ALL_TODOS);
  const data = res.data;
  const errors = res.errors;

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.