Skip to content

Commit

Permalink
refactor, update docs, fix db env
Browse files Browse the repository at this point in the history
  • Loading branch information
DenverCoder1 committed Nov 28, 2023
1 parent 63c3297 commit b0c7057
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 51 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DB_URL= # Mongo connection string in the format mongodb+srv://<username>:<password>@<cluster>.mongodb.net/<dbname>?retryWrites=true&w=majority&tls=true
PORT=5000 # Port to run the server on (default: 5000)
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install modules
run: yarn install-modules
run: yarn install-all
- name: Run build
run: yarn build
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install modules
run: yarn install-modules
run: yarn install-all
- name: Run lint script
run: yarn lint
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: conventional Changelog Action
id: changelog
uses: TriPSs/conventional-changelog-action@v3.7.1
with:
github-token: ${{ secrets.CHANGELOG_RELEASE }}
output-file: 'false'
version-file: './package.json,./client/package.json'
version-file: './package.json,./server/package.json'

- name: create release
uses: actions/create-release@v1
Expand Down
20 changes: 1 addition & 19 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,8 @@ ports:
- port: 5000
onOpen: open-preview
tasks:
- init: yarn install && yarn install-client
- init: yarn install-all
command: yarn dev
github:
prebuilds:
# enable for the master/default branch (defaults to true)
master: true
# enable for all branches in this repo (defaults to false)
branches: false
# enable for pull requests coming from this repo (defaults to true)
pullRequests: true
# enable for pull requests coming from forks (defaults to false)
pullRequestsFromForks: true
# add a check to pull requests (defaults to true)
addCheck: true
# add a "Review in Gitpod" button as a comment to pull requests (defaults to false)
addComment: false
# add a "Review in Gitpod" button to the pull request's description (defaults to false)
addBadge: false
# add a label once the prebuild is ready to pull requests (defaults to false)
addLabel: false
vscode:
extensions:
- esbenp.prettier-vscode@1.7.0:EbyqFvwe32qQBptkOgfQpQ==
18 changes: 15 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ cd custom-icon-badges
### Installing dependencies

```bash
yarn && yarn install-client
yarn install-all
```

### Config vars

To work with a database, add a `.env` file on the root level with the following:
To work with a database, add a `.env` file in the root directory with the following:

```bash
DB_URL=mongodb+srv://<username>:<password>@<cluster>.mongodb.net/<dbname>?retryWrites=true&w=majority&tls=true
Expand All @@ -40,6 +40,12 @@ The URL should be the URL provided by MongoDB and the database should have a col

More info on setting up a free Atlas database on [MongoDB's documentation](https://docs.atlas.mongodb.com/getting-started/).

Optionally, you can also set the `PORT` variable to change the port the server runs on (by default, it runs on port 5000):

```bash
PORT=5000
```

### Build and run the app locally

```bash
Expand All @@ -62,12 +68,18 @@ yarn start-client

<http://localhost:3000/> will be opened in your browser

### Linting
### Show linting errors

```bash
yarn lint
```

### Fix linting errors

```bash
yarn fix
```

### Commit style guide

We use [Conventional Commits](https://conventionalcommits.org/) for commit messages.
Expand Down
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
{
"name": "custom-icon-badges-client",
"version": "0.12.1",
"private": true,
"description": "Allows users to more easily use their own icons and logos in shields.io badges",
"author": "Jonah Lawrence",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/DenverCoder1/custom-icon-badges.git"
},
"bugs": {
"url": "https://github.com/DenverCoder1/custom-icon-badges/issues"
},
"dependencies": {
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.0.0",
Expand Down Expand Up @@ -41,7 +50,7 @@
"lint": "yarn eslint . --ext .ts,.tsx && cd server && yarn lint",
"fix": "yarn eslint . --ext .ts,.tsx --fix && cd server && yarn fix",
"dev": "yarn lint && yarn build && yarn start",
"install-modules": "yarn install && (cd server && yarn install)"
"install-all": "yarn install && cd server && yarn install"
},
"browserslist": {
"production": [
Expand Down
1 change: 1 addition & 0 deletions server/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
node_modules
# don't lint build output
dist
server/dist
# don't lint nyc coverage output
coverage
15 changes: 5 additions & 10 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import express from 'express';
import rateLimit from 'express-rate-limit';
import router from './routes/routes.js';

const __dirname = path.dirname(new URL(import.meta.url).pathname);
dotenv.config({ path: path.join(__dirname, '.env') });
dotenv.config({ path: path.resolve('..', '.env') });

const PORT = process.env.PORT || 5000;
const PORT = process.env.PORT ?? 5000;
const BUILD_PATH = path.resolve('..', 'build');

const app = express();
app.set('trust proxy', 1);
app.use(express.json());
app.use(express.static(BUILD_PATH)); // For the production server
app.use(express.static(BUILD_PATH));
app.use(router);

// set rate limit on post requests
Expand Down Expand Up @@ -45,12 +44,8 @@ const server = app.listen(PORT, () => {
console.log(`Server listening at port ${PORT}`);
});

// Must get at the end of the file!
/*
Endpoint: /
Returns as the response: The base webpage of the site.
*/
app.get('/*', (req, res) => {
// Display the react app on the root path
app.get('/', (req: express.Request, res: express.Response) => {
res.sendFile(path.join(BUILD_PATH, 'index.html'));
});

Expand Down
13 changes: 2 additions & 11 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"name": "custom-icon-badges",
"version": "0.12.1",
"description": "Allows users to more easily use their own icons and logos in shields.io badges",
"author": "Jonah Lawrence",
"license": "MIT",
"private": true,
"type": "module",
"dependencies": {
"@primer/octicons": "^19.8.0",
"@types/express": "^4.17.20",
Expand All @@ -25,19 +24,11 @@
"devDependencies": {
"eslint": "^7.32.0"
},
"type": "module",
"scripts": {
"start": "node dist/index.js",
"build": "yarn install && yarn tsc",
"test": "exit 0",
"lint": "yarn eslint . --ext .ts,.tsx",
"fix": "yarn eslint . --ext .ts,.tsx --fix"
},
"repository": {
"type": "git",
"url": "git+https://github.com/DenverCoder1/custom-icon-badges.git"
},
"bugs": {
"url": "https://github.com/DenverCoder1/custom-icon-badges/issues"
}
}
4 changes: 4 additions & 0 deletions server/services/icons/iconDatabase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import dotenv from 'dotenv';
import monk, { FindResult } from 'monk';
import path from 'path';
import IconsService from './IconsService.js';
import { setLogoColor } from '../logoColor.js';

dotenv.config({ path: path.resolve('..', '.env') });

const DB_NAME = 'custom-icon-badges';
const DB_URL = process.env.DB_URL ?? `mongodb://localhost:27017/${DB_NAME}`;
const db = monk(DB_URL);
Expand Down

0 comments on commit b0c7057

Please sign in to comment.