Skip to content

SanctumLabs/space-xplorer-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Space Xplorer Server

Codacy Badge Code scanning NodeJS Package Space Xplorer Docker build Github Release Tests Codacy Badge

Server that interfaces with SpaceX API to allow users to book seats on the next SpaceX launch

Prerequisites

A couple of things you need to have on your local development environment include:

Docker & docker-compose

You need to ensure you have Docker & Docker Compose installed on your local development environment, as they are used when running containers. More explanation on containers can be found in the links provided for Docker and docker-compose

Node & NPM(or Yarn)

You require a working version of NodeJS as this is a Node based application and npm or yarn for package management. Yarn has been preferred for this application, but npm can be used as well

Getting started

Getting started is quite straighforward and the following steps should get you up and running.

$ git clone https://github.com/Wyvarn/space-xplorer-server.git
$ cd space-xplorer-server
$ yarn install
# if using npm
$ npm install

This will install the required dependencies

Run database

This uses a PostgreSQL DB as a persistence provider. Thus, for local development, you will need a running instance of this DB. This is provided with Docker for local development.

To get this DB up & running. First set the environment variables that you will need when running it:

cp .env.example .env
cd prisma
cp .env.example .env

Prefill the .env file created with the relevant details for the environment variables you will use in the project.

Now you can start up the DB as below:

docker-compose up

This will start up the DB

Now you can perform migrations as below:

yarn migrate:up

This will run migrations as specified in the migrations folder

To create a new migration, simply change the schema in the schema and then run a migration with:

yarn migrate:create
yarn migrate:up

NOTE: These commands are interchangebale with NPM(npm)

Run application

Now you are all set to run the application:

yarn start

That should pretty much be it when running the application. You can now navigate to http://localhost:4000 on your browser & should be able to view the GraphQL client browser & create queries.

Deployment

This application has been built for it to be deployed on any environment:

  1. As a vanilla deployment as a server with a process manager or with Node
  2. Running in a Docker container in an environment that supports Docker runtime
  3. In a Kubernetes cluster inside a Pod

All the configurations have been put in place for this application to run in a predictable manner.

Only a few things you will need to do:

  1. Set environment variables in your environment as specified in the .env.example

  2. Ensure that DB migrations are run before application start

    • If running in a vanilla Node JS environment, you can use the npm scripts provided to run migrations
    • If running in a Docker runtime supported environment, you can use the Dockerfile.migrations file to build an image specifically for running DB migrations. This will run & exist successfully
    • If running in a Kubernetes supported environment using Deployments, the templates specified in the k8s folder will give a hint on how to enable these migrations to run before application start using init containers

And that should be it to get you a working running API with GraphQL.

Built with:

  1. TypeScript
  2. Apollo Server
  3. Prisma
  4. Jest