Skip to content

Commit

Permalink
Merge pull request #104 from neatht/v14.0.0/master
Browse files Browse the repository at this point in the history
🚀 Version 14.0.0
  • Loading branch information
taylor-johnston authored Nov 20, 2020
2 parents f4c8786 + 2c9f405 commit d7a3a89
Show file tree
Hide file tree
Showing 102 changed files with 4,292 additions and 869 deletions.
62 changes: 59 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<h1 align="center">🛰️<br>Glowbal</h1>

<h1 align="center">
<img width="100px" src="client/src/logo-rocket.svg"></img>
<br>
Glowbal
</h1>

<div align="center">
<strong>An ePortfolio web app built on React and Express</strong>
Expand Down Expand Up @@ -30,13 +35,62 @@

These instructions will help you get a copy of the project up and running for development and testing. This project runs on an Express backend and React frontend with TypeScript. You will need `npm` and `yarn` installed to start.

#### 🤫 Environment Variables

Both the frontend and backend make use of environment variables that will need to be present out before building.

In both the `client` and `api` directories, there is an example `.example.env` which should be filled out and renamed to `.env`

`api/.env`

```
# Server settings
NODE_ENV=development
SERVER_PORT=5000
# Authentication settings
EMAIL_KEY=https://example.com/email
AUTH0_AUDIENCE=
AUTH0_ISSUER=
JWKS_URI=
# SSL settings
SSL_CRT_FILE=../server.cert
SSL_KEY_FILE=../server.key
# Database settings
DB_ENDPOINT=
DB_NAME=
DB_USERNAME=
DB_PASSWORD=
# AWS
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_BUCKET_NAME=
```

`client/.env`
```
# API settings
REACT_APP_API_URL=https://localhost:5000/api/
# Authentication settings
REACT_APP_AUTH0_DOMAIN=
REACT_APP_AUTH0_CLIENT_ID=
REACT_AUDIENCE=
```

The keys used in the default deployment can be found in the #keys channel in Slack.

#### :lock: SSL certificate
Before building either servers, you will need an SSL certificate.
Before running the API, you will need an SSL certificate.

In the root directory, start by creating a certificate:
```
openssl req -x509 -newkey rsa:4096 -keyout server.key -out server.cert -days 365 -nodes
```
To specify the certificates, in both `client` and `api`, add the following lines to the `.env`:
To specify the certificates, in `api`, add the following lines to the `.env`:
```
SSL_CRT_FILE=../server.cert
SSL_KEY_FILE=../server.key
Expand Down Expand Up @@ -114,6 +168,8 @@ In should open automatically, however the app can be found at:
localhost:6006
```

Note that some components will require the use of the API so you should also run the API server locally at the same time

### :computer: API: Stoplight

The backend routes are documented using [Stoplight](https://camelcase.stoplight.io)
Expand Down
24 changes: 24 additions & 0 deletions api/.example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Server settings
NODE_ENV=development
SERVER_PORT=5000

# Authentication settings
EMAIL_KEY=https://example.com/email
AUTH0_AUDIENCE=
AUTH0_ISSUER=
JWKS_URI=

# SSL settings
SSL_CRT_FILE=../server.cert
SSL_KEY_FILE=../server.key

# Database settings
DB_ENDPOINT=
DB_NAME=
DB_USERNAME=
DB_PASSWORD=

# AWS
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_BUCKET_NAME=
20 changes: 16 additions & 4 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
"express-validator": "^6.6.1",
"jsonwebtoken": "^8.5.1",
"jwks-rsa": "^1.10.1",
"node-cache": "^5.1.2",
"npm-run-all": "^4.1.5",
"passport": "^0.4.1",
"passport-facebook": "^3.0.0",
"pg": "^8.3.3",
"pm2": "^4.5.0",
"sequelize": "^6.3.5",
"systeminformation": "^4.30.1",
"uuid": "^8.3.1"
},
"devDependencies": {
Expand All @@ -45,7 +47,7 @@
"@types/jest": "^26.0.15",
"@types/node": "^14.11.2",
"@types/supertest": "^2.0.10",
"jest": "^26.6.1",
"jest": "^26.6.3",
"nodemon": "^2.0.4",
"supertest": "^6.0.0",
"ts-jest": "^26.4.3",
Expand Down
9 changes: 9 additions & 0 deletions api/src/cache/cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import CacheService from './service';

const profileTtl = 60 * 60 * 1;
const ttl = 60 * 5 * 1;
const ownProfileTtl = 60 * 168 * 1;
export const profileCache = new CacheService(profileTtl, 'profileCache');
export const mediaCache = new CacheService(ttl, 'mediaCache');
export const projectCache = new CacheService(ttl, 'projectCache');
export const ownProfileCache = new CacheService(ownProfileTtl, 'ownProfileCache');
56 changes: 56 additions & 0 deletions api/src/cache/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* Service to create cache storage for API endpoints */
import NodeCache from 'node-cache';

export default class CacheService {
cache: NodeCache;
name: string;

constructor(ttlSec: number, name: string = 'Cache') {
this.cache = new NodeCache({ stdTTL: ttlSec, checkperiod: ttlSec * 0.2, useClones: false });
this.name = name;
}

get(key: string, storeCallback: () => Promise<any>) {
const value: any = this.cache.get(key);

if (value) {
console.log(`${this.name}: key ${key} exists in cache. Retrieving from cache...`)
return Promise.resolve(value);
}

console.log(`${this.name}: key ${key} doesn't exist in cache. Accessing DB and storing in cache...`)

return storeCallback().then(res => {
this.cache.set(key, res);
return res;
})
}

set(key: string, obj: any) {
console.log(`${this.name}: key ${key} SET in cache`)
this.cache.set(key, obj);
}

del(key: string) {
console.log(`${this.name}: key ${key} DELETED from cache`)
this.cache.del(key);
}

delStartsWith(startStr: string = '') {
if (!startStr) {
return;
}

const keys = this.cache.keys();

for (const key of keys) {
if (key.indexOf(startStr) === 0) {
this.del(key);
}
}
}

flush() {
this.cache.flushAll();
}
}
Loading

0 comments on commit d7a3a89

Please sign in to comment.