GithubHelp home page GithubHelp logo

isabella232 / api-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cdnjs/api-server

0.0 0.0 0.0 6.19 MB

๐Ÿ“ก API server for api.cdnjs.com - The #1 free and open source CDN built to make life easier for developers.

Home Page: https://api.cdnjs.com

License: MIT License

JavaScript 98.86% Shell 1.04% Makefile 0.10%

api-server's Introduction

< cdnjs >

The #1 free and open source CDN built to make life easier for developers.


cdnjs API Server

Looking for the documentation on our API?

cdnjs API docs

Getting Started

This project runs on Node.js. Please make sure you have a version installed that matches our defined requirement in the .nvmrc file for this project.

Included with this project is a dependency lock file. This is used to ensure that all installations of the project are using the same version of dependencies for consistency.

You can install the Node dependencies following this lock file by running:

npm ci

Once the dependencies are installed, you need to get a copy of all the data that the API server requires to run. This can be done by running:

npm run build

With the data fetched, the API server is ready to run in development mode. To start the server in development mode, run:

npm run dev

Updating Data

To update your data, you can simply run npm run build again, which will update the tutorial repo clone originally created by this script.

Once you have updated your data locally, you will need to restart the development server for it to pick up the new data. In production, the app includes its own update job that runs every ten minutes, calling the same logic as npm run build and then loading that data into memory.

The npm run build script performs the following task, via update/worker.js:

Error Logging

We make use of Sentry to handle our error logging. To enable Sentry in the API server, set the SENTRY_DSN environment variable to a valid DSN URL from Sentry.

Alongside the normal error catching that Sentry provides in Node.js & Express, we also fire out custom error events for certain issues:

  • Missing SRI entry is fired if there is no SRI hash for a file
  • Bad entry in Algolia data is fired if an entry in Algolia is falsey, or if its name is falsey
  • Bad entry in packages data is fired if a package is falsey, or if its name/version is falsey

Production Deployment

To deploy this API server to production, it should be as simple as cloning this repository, running npm run build to fetch the initial data for the server and then running npm run start.

To change the port that the app binds to, set the PORT environment var when running the script. For our Heroku deployment, this is set automatically by Heroku.

Removing submodules and then cloning the respective repositories is used to update data for production deployments due to how Heroku sets up the app, with the final app directory not being an initialised Git repo.

Testing and Linting

Our full set of tests (linting & test suite) can be run at any time with:

npm test

You can also run the tests with their own API server running in development mode using:

npm run test:with-server

Note, as this starts an instance of the API server, data for it must be available. This can be done by running npm run build, before starting the server/tests.

(This is what the CI in this repository uses for every commit).

Linting

Included in this repository are an eslint config file as well as an editorconfig file to help with ensuring a consistent style in the codebase for the API server.

To help enforce this, we use both eslint and echint in our testing. To run eslint at any time, which checks the code style of any JavaScript, you can use:

npm run test:eslint

eslint also provides automatic fixing capabilities, these can be run against the codebase with:

npm run test:eslint:fix

The more generic rules defined in the editorconfig file apply to all files in the repository and this is enforced by echint, which can be run at any time with:

npm run test:echint

Testing

This project uses Mocha and Chai (http) to test the API server. The tests attempt to validate every route on the API to ensure that no breaking changes have been made, though there is no promise that this is perfect, a human should always review changes!

The mocha test suite can be run at any time with the following command, assuming that the API server is running locally on port 5050 (or on the port defined with the environment variable PORT):

npm run test:mocha

You can also start the mocha test suite with a dedicated API server running in development mode on port 5050 (or on the port defined with the environment variable PORT) by running:

npm run test:mocha:with-server

api-server's People

Contributors

dependabot[bot] avatar klausenbusk avatar masad-frost avatar mattipv4 avatar xtuc avatar

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.