# nextjs-github-browser
[](https://github.com/topheman/nextjs-github-browser/actions/workflows/ci.yml)
[](https://github.com/topheman/nextjs-github-browser/actions/workflows/e2e.yml)
[](https://dashboard.cypress.io/projects/6ihjj6/runs)
[](https://nextjs-github-browser.vercel.app/explore/storybook/index.html)
[](http://nextjs-github-browser.vercel.app/)
This project is a reimplementation of the main features of the [github.com](https://github.com) website in **NextJS**.
- Checkout the **demo** on **[nextjs-github-browser.vercel.app](https://nextjs-github-browser.vercel.app)**
- Browse the [online storybook](https://nextjs-github-browser.vercel.app/explore/storybook/index.html)
- Browse the [Cypress Dashboard](https://dashboard.cypress.io/projects/6ihjj6) (with the reports of the e2e tests run on CI)
## Prerequisites
- Nodejs >=14
- npm >=6
## Install
```sh
git clone https://github.com/topheman/nextjs-github-browser.git
cd nextjs-github-browser
npm install
```
## Setup
This project uses the [Github GraphQL Apis](https://docs.github.com/en/graphql). You will need to [generate a personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token).
- Create a `.env.local` file
- Add `GRAPHQL_API_TOKEN=***` to the file with your own token
## Development
```shell
npm run dev
```
This will start a development server on [http://localhost:3000](http://localhost:3000).
### Mocking
This project is shipped with built-in mocking for the graphql layer. It works for both client-side and server-side rendering.
- `MOCKS_MODE=record npm run dev` : will record any graphql request into `.tmp/mocks`
- `MOCKS_MODE=replay npm run dev` : will replay the mocks if available (if not, will let the request through)
You can use `MOCKS_MODE` with `record` / `replay` also on `npm start`.
You can override the target of the folder where the mocks are recorded by using `MOCKS_TARGET=./tmp/my/specific/folder` for example.
## Storybook
```sh
npm run storybook
```
This will start the storybook server on [http://localhost:6006](http://localhost:6006).
## Build
```sh
npm run build
```
This will build the a production version of the website in the `.next` folder.
For production, we want to expose the storybook, to do that:
```sh
npm run build:all
```
## Production
First, you need to build your project running `npm run build:all`, then:
```shell
npm start
```
This will launch a production server on [http://localhost:3000](http://localhost:3000).
You can change the port passing a `PORT` env var like: `PORT=8080 npm start`.
## Test
### Unit
The project contains unit tests run with jest (the react part is relying on [@testing-library/react](https://testing-library.com/docs/react-testing-library/intro/))
```sh
npm run test
```
### Cypress
To run the cypress end-to-end test, launch a server in a terminal (in [dev mode](#development) or [production mode](#production)).
Then start the cypress test either:
- In gui mode: `npm run cy:open`
- In headless mode: `npm run cy:run`