12/06/2020 - gatsby contentful start + netlify + gatsby cloud



  • i do not use a local environment, node modules takes up too much space
  • using codesandbox (aka csb)
    • csb features
      • templates - aka environment, you could have node, create-react-app etc
      • so usually i will use csb and search for the relevant template to try out new technologies
  • csb restrictions to keep in mind
    • cli commands eg gatsby cli or contentful cli are not allowed, aka npm i global
    • ready only server terminal, to run commands, open a new terminal after the container is ready
    • command line npm install not allowed, use add dependencies
  • gatsby uses a command line for installing starters
    • cli does not work on csb so have to clone the repo into a new sandbox 
    • it will generate a new sandbox with the files in the repo
  • csb/explorer/package json
    • the app will crash at first - there are issues with
      • missing start script
      • dependencies - csb only downloads the main dependencies
      • secret keys
      • main or entry needs to be n/a as gatsby is serverless
    • have to alter the package json so there is a start script and it points to develop script
    • also package json have to install the dev dependencies and delete the saved entries in the dependencies
    • add the dependencies in csb/explorer/dependencies - search names
      • csb does not allow command cli npm install
  • csb/new terminal
    • go contentful for a setup
    • on the set up intro, there's a cli command walkthrough
    • still needs the contentful and contentful-cli
    • to walkthrough the cli commands,
    • open a new terminal, the server terminal is ready only
    • then copy past the commands to the new terminal
    • csb/server/secret 
      • add in the client secrets into the csb/server control panel/secret keys
      • since the code is already using dotenv which uses process.env variables, just copy the names of the variables and set the same for the keys name value pairs
    • there is one more api key which doesn't seem to be included in the cli command walkthrough, but was able to find by googling contentful api key or something like that which points to a api key page in the contentful website - provided you are logged in
    • check your contentful space, and model, there should be new entry
  • after the gatsby folder import + contentful execute command cli + some tweaking
    • your site should be ready
    • restart the container or the server
    • the csb browser should render correctly
    • to go to the graphiql interface, csb/port/graphiql, click it and it will open another csb browser tab with __ instead of just /
  • git remote origin master
    • csb/git/create repo doesn't work for me, ran for quite a while but nothing happened
    • i wasn't too sure if the folder was too huge and which files to leave out
    • had to do git commands in csb/terminal
    • github.com, create an empty repo
    • git remote set-url but embed your username and password into the url for auth purpose
    • git init, git add . , git remote origin master
    • to verify your origin url, use git remote, origin
  • netlify/gatsbycloud/contentful
    • gatsbycloud requires a git repo
    • basically a few click arounds to link up the accounts
    • then added a new post in contentful
    • and used gatsby cloud to trigger the build
    • went to the netlify url, saw the changes were updated, even the one in csb
  • thoughts
    • not so used to serverless concept and keep on running build and the hot reload
    • gatsby uses graphql to query data, so some background is need to get up and running
    • the hooks is really powerful
    • since this is on csb, it is not a local environment 
    • i knew this through brad traversy's youtube channel, one where he was recommending 2019 web technologies, also the mention of JAMstack on the internet and after watching traversy's gatsby tutorial
    • he mentioned that gatsby was practical and useful for the freelance web dev because it offered starters, so basically you have a ton of boiler and config out of the package (saves a lot of coding), and netlify is really easy to use, serverless also means less maintainence
    • i feel with gatsby, because its a framework, its opinionated, so you won't have the joy and the tendency to learn and think about how you would code something because the tools are there and ready for you to use. 
    • frameworks can be less fun, because there is a lot to memorise, it can also be very scary for new beginners to digest, because there's so many advanced features and concept foreign to new JS coders
    • suggest to read through, and then get your hands dirty so you won't overthink and worry you have so much you don't know
    • what i like about it is it comes with starters, so you could be a total noob like me and have a snazzy web app with its own cms
      • not too sure about how the pwa works, not yet tested the feature
      • up on my list is auth, stripe checkout, programmatic generation of data - as opposed to gatsby taking markdown files and parsing them into the data set (aka a static generator), it is not just that.
    • i would call gatsby a turbo charged react wrapper? one that lets you avoid webpack - which i am totally unfamiliar with
  • all in all, reading the docs gave me anxiety, playing with the code (and seeing results) made me feel better and also see the benefits of this new technology
  • there is a youtube tutorial, it should be a detailed step by step - probably uses local environment, i ended diy-ing during the middle of the 1st video, its a playlist.

Comments

Popular posts from this blog

green tea bitch

song

20231104