Skip to content

Latest commit

 

History

History
85 lines (58 loc) · 2.2 KB

BEST_PRACTICES.md

File metadata and controls

85 lines (58 loc) · 2.2 KB

Best Practices

Set path in micro:

https://github.com/zeit/micro/blob/master/errors/path-not-existent.md

Add rate limiting to the api

const rateLimit = require("my-rate-limit");
module.exports = async (req, res) => {
  try {
    await rateLimit(req);
  } catch (err) {
    if (429 == err.statusCode) {
      // perhaps send 500 instead?
      send(res, 500);
    }
  }
};

Node.js helpers for apis on Zeit Now

https://zeit.co/docs/v2/serverless-functions/supported-languages#node.js-helpers

Zeit Now customized API endpoints

https://thecloud.christmas/2019/8

Use Github CDN for content

curl https://raw.githubusercontent.com/hwclass/buildless-site/master/README.md

Read a readme file from github in a certain document range

curl https://raw.githubusercontent.com/hwclass/awesome-buildless/master/README.md | sed -n '/### Articles/,/### Tutorials/p'

marked can be used to parse markdown from an endpoint to convert into HTML string

marked

HTMLCollection object collection is only iterable after applying Array.from

Update npm to the latest version

npm install -g npm@latest

Add rel="noopener" or rel="noreferrer" into a tags with target="_blank" to prevent sec.

<a href="..." target="_blank" rel="noopener" />

It is recommended to use the following header with zeit now to keep the content in sync with the remote resource while/after serving from the edge cache:

Cache-Control: s-maxage=1, stale-while-revalidate

Better waiting to get Inter font introduced to Google Fonts PR.

Spacer between spaced-evenly elements in css grid:

flex-grow: 0.1;

Import assets in the Head via Fresh runtime

// import asset function from Fresh runtime
import { asset, Head } from "$fresh/runtime.ts";

// refer to the CSS file within <Head>...</Head>
<link rel="stylesheet" href={asset("style.css")} />;