manuel-valles / deno-nasa

A full stack app with Deno

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deno | The NASA Project

A full stack app written in Deno and Oak.

Deployed in Heroku with Buildpacks. Frontend: https://deno-nasa.herokuapp.com/index.html

  • Current libraries/frameworks available for Deno:

  • Oak Basics:

    • Current version: https://deno.land/x/oak@v6.3.0/mod.ts
    • Oak Documentation: https://doc.deno.land/https/deno.land/x/oak@v6.3.0/mod.ts
    • Example Context Response Headers (Middleware): contextHeaders
    • NOTE: Challenges Page found (although no new challenges out since 2019): https://adventofcode.com/2019/about
    • allowedMethods() allows other machines to know what routes our app supports and to get specific status codes back from the requests.
      app.use(api.allowedMethods());
      • With this implementation, if you try to use a method that our app doesn't include, it returns a 405 Method Not Allowed instead of a just a 404.
      • NOTE: The OPTIONS method, returns what methods are currently allowed by our app: optionsAllowed
    • Deno Error Handling can be set in the main/mod file as a middleware with the try-catch, and then log the errors within the EventTarget (https://developer.mozilla.org/en-US/docs/Web/API/EventTarget): app.addEventListener(). You can throw more specific errors with the Context: ctx.throw(501, "Sorry planets aren't available!"), although Oak won't show the message as body for statuses 50X.
    • The Context has the request.body() that parses the body appropriately (JSON).
  • Heroku Deployment

    • Create Procfile for Buildpacks deployments with Heroku & Deno: web: deno run --allow-net --allow-read --cached-only ./src/mod.ts --port=${PORT}

    • Buildpacks info: https://devcenter.heroku.com/articles/buildpacks

    • $ heroku login

    • $ heroku create --buildpack https://github.com/chibat/heroku-buildpack-deno.git deno-nasa

    • $ git push heroku main

    • You can restart the app:

      • From the platform (Restart all dynos):

        restartHerokuApp

      • From the console (individual dyno): $ heroku ps:restart web.1. Where web.x is the name and number of your dyno.

    • Logs: $ heroku logs --tail

About

A full stack app with Deno


Languages

Language:TypeScript 41.2%Language:HTML 30.3%Language:JavaScript 27.4%Language:CSS 1.1%