Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use APi data for the datasource #7

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
}
},
"rules": {
"react/prop-types": 0
"react/prop-types": 0,
"no-extra-semi": 0,
"semi": 0,
"quotes": "off",
"space-before-function-paren": "off",
"comma-dangle": "off"
}
}
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
# Stacks Status

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://mit-license.org/)
[![Pull Requests Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](http://makeapullrequest.com)

This repository contains the code for the [**Stacks Blockchain Status Page**](https://status.stacks.org/) code used by the [Stacks Foundation](https://www.stacks.org) to display blockchain metrics.
This is a next.js react app that reads locally stored metric data from a postgres database, and periodically will fetch data from [https://stacksonchain.com/](https://stacksonchain.com/) to refresh the displayed data.

This is a next.js react app that reads locally stored metric data from a postgres database, and periodically will fetch data from [https://stacksonchain.com/](https://stacksonchain.com/) to refresh the displayed data.

## Getting Started

* PostgreSQL is a required dependency
example with Docker:
- PostgreSQL is a required dependency
example with Docker:

```bash
$ docker run -d \
--rm \
--name postgres \
-p 5432:5432 \
-e POSTGRES_PASSWORD=postgres \
-v /tmp/postgres_data:/var/lib/postgresql/data \
postgres:14-alpine
-v ./postgres_data:/var/lib/postgresql/data \
postgres:15-alpine
```

```bash
Expand Down Expand Up @@ -47,13 +48,15 @@ yarn build && yarn start
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

## Refreshing the data

There are 2 paths via the `/api` route to refresh the data, and 1 standalone script with not authentication

1. `/api/refresh` - this path is used with [upstash](upstash.com) [docs](https://docs.upstash.com/qstash/quickstarts/vercel-nextjs)
2. `/api/refresh_local` - this path is used with a local key defined below `API_SECRET_KEY`
3. `node lib/standalone_check.js` - [package.json](./package.json) will need to be set to `"type": "module"` to run this

To refresh the data, you can run a `curl` command like the following:

```bash
$ curl -sLw '\n' \
--request POST \
Expand All @@ -62,31 +65,29 @@ $ curl -sLw '\n' \
```

With upstash:

```bash
$ curl -sL \
--request POST \
--url "https://qstash.upstash.io/v1/publish/<url of app>/api/refresh" \
--header "Authorization: Bearer <refer to upstash docs>"
```


## Adding more checks
In folder `./status_checks`, each json file defines an API request to [stacksonchain](https://stacksonchain.com).
To add a new check, copy/paste an existing file and modify the query (be sure to set `"disabled": false` to enable the check).

In folder `./status_checks`, each json file defines an API request to [stacksonchain](https://stacksonchain.com).
To add a new check, copy/paste an existing file and modify the query (be sure to set `"disabled": false` to enable the check).
Refer to the json schemas:
* [status_checks_array.schema.json](./status_checks_array.schema.json)
* [status_checks_string.schema.json](./status_checks_string.schema.json)

- [status_checks_array.schema.json](./status_checks_array.schema.json)
- [status_checks_string.schema.json](./status_checks_string.schema.json)

## Configuration

### Environment Variables

| Name | Description | Default Value |
| -------------------------------------- | ----------------------------------- | --------------------------------------------------------- |
| `NODE_ENV` | Sets the node environment | `development` |
| `DATABASE_URL` | Postgresql connection URI | `postgresql://postgres:postgres@localhost:5432/postgres` |
| `API_SECRET_KEY` | Key to refresh the data via POST | `secret` |



| Name | Description | Default Value |
| ---------------- | -------------------------------- | -------------------------------------------------------- |
| `NODE_ENV` | Sets the node environment | `development` |
| `DATABASE_URL` | Postgresql connection URI | `postgresql://postgres:postgres@localhost:5432/postgres` |
| `API_SECRET_KEY` | Key to refresh the data via POST | `secret` |
16 changes: 11 additions & 5 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
export function makeSerializable(o) {
return JSON.parse(JSON.stringify(o));
}

export function makeSerializable (o) {
return JSON.parse(JSON.stringify(o))
export function convertEpoch(date) {
const myDate = new Date(date * 1000);
return myDate.toGMTString();
}

export function convertEpoch (date) {
const myDate = new Date(date * 1000)
return myDate.toGMTString()
// pages/api/user
export async function getData(url) {
const response = await fetch(url);
const jsonData = await response.json();
return jsonData;
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
"express": "^4.18.1",
"express-winston": "4.2.0",
"next": "12.3.1",
"prisma": "^4.4.0",
"prisma": "5.8.0",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@nextui-org/react": "^1.0.0-beta.10",
"@prisma/client": "^4.4.0",
"@prisma/client": "5.8.0",
"@svgr/webpack": "^6.5.0",
"@upstash/qstash": "^0.1.8",
"eslint": "^8.27.0",
Expand Down
Loading
Loading