Skip to content

Commit

Permalink
feat: initial-commit
Browse files Browse the repository at this point in the history
First commit that has the full functionlity of a rest auth application.

BREAKING CHANGE: Initial Commit
  • Loading branch information
Manny authored and Manny committed Jul 6, 2020
0 parents commit 9a5bf3d
Show file tree
Hide file tree
Showing 47 changed files with 2,657 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
PORT=5000
NODE_ENV=development
VERSION=1.0.0

JWT_SECRET=jwt_secret_key
JWT_ISSUER=api.localhost
JWT_AUDIENCE=api.localhost
JWT_MAX_AGE=900

JWT_REFESH_SECRET=jwt_refresh_secret_key
JWT_REFRESH_MAX_AGE=604800

JWT_RESET_SECRET=jwt_reset_secret_key
JWT_RESET_MAX_AGE=300

CSRF_COOKIE_PREFIX=nodetscookie
CSRF_COOKIE_MAXAGE=900

MAILGUN_API_URL=
MAILGUN_SECRET_KEY=
MAILGUN_DOMAIN=

EMAIL_FROM=noreply
EMAIL_SUBJECT_RESET="Reset Your Password"
EMAIL_SUBJECT_CONFIRM="Confirm Account"
EMAIL_URL_RESET_PASSWORD=http://localhost:3000/auth/reset
EMAIL_URL_CONFIRM_ACCOUNT=http://localhost:3000/auth/confirm
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
build
dist
*.log
coverage
prisma/migrations/*.lock
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'prettier/@typescript-eslint',
'plugin:jest/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
},
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
env: {
jest: true,
},
};
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules/
build
dist
*.log
.env
yarn.lock
package-lock.json
.eslintcache
**/.DS_Store
coverage
prisma/migrations/*.lock
6 changes: 6 additions & 0 deletions .huskyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "./node_modules/.bin/lint-staged"
}
}
5 changes: 5 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"*.{ts,js,json,md}": [
"prettier --write"
]
}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12.18.1
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
build
dist
*.log
coverage
prisma/migrations/*.lock
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"proseWrap": "always"
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.formatOnPaste": true
}
165 changes: 165 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
# NodeTS REST Auth Bootstrap

Original based off the
[NodeTS Bootstrap](https://github.com/codingwithmanny/nodets-bootstrap)
repository.

This is a base NodeJS REST Auth TypeScript App built with express and all
configurations files included.

This repository is meant to be a base to build on top of for building an API.

## Copy This App

```bash
git clone https://github.com/codingwithmanny/nodets-rest-auth-bootstrap myproject;
cd myproject;
rm -rf .git;
git init -y;
git remote add origin https://github.com/your/newrepo;
```

## Requirements

- NodeJS 12.18.1 or NVM
- Docker or Postgres Database
- MailGun account for emails

## Local Setup

While in project directory:

**0 - (Optional) NVM Installation**

```bash
nvm install;
```

**1 - Install Depencies**

```bash
yarn install; # npm install;
```

**2 - Start Database**

Using `Docker`

```bash
docker run -it -d -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=secret -e POSTGRES_DB=postgres --name nodetsdb postgres;
```

**3 - Configure Database Environment Variables**

**File:** `./prisma/.env`

```bash
DATABASE_URL="postgresql://postgres:secret@localhost:5432/postgres?schema=public"
```

**4 - Run Migrations**

```bash
yarn db:migrate; # npm run db:migrate;
```

**5 - Setup ENV VARS**

**NOTE:** Make sure to fill them with the correct ENV Variables

```bash
cp .env.example .env;
```

**6 - Server Start**

`Development:`

```bash
yarn dev; # npm dev;
```

`Production:`

```bash
yarn start; # npm start;
```

**7 - (Optional) Seeding**

```bash
yarn db:seed:all; # npm run db:seed:all
```

## Production Commands

`Build`

```bash
yarn build; # npm run build
```

`Build & Serve`

```bash
yarn start; # npm start
```

## Tests

`All Tests`

```bash
yarn test; # npm run test;
```

`Jest Watch`

```bash
yarn test:jest; # npm run test:jest;
```

`Jest Coverage`

```bash
yarn test:coverage; # npm run test:coverage;
```

`Eslint`

```bash
yarn test:lint; # npm run test:lint
```

## Development

Guidelines for development

### New Migration

There is a checklist for creating a new migration:

- [ ] - Create new model in `./prisma/schema.prisma`
- [ ] - Double check that it adheres to the criteria
- [ ] - `yarn db:save;`
- [ ] - `yarn db:gen;`
- [ ] - Create new sed `yarn db:seed:gen` and modify `NEW.ts` with name
`ModelNameSeed.ts`
- [ ] - Run migrations `yarn db:migrate`
- [ ] - Write tests

Create new models in the `./prisma/schema.prisma` file.

**Criteria:**

- Singular: `User` _NOT_ `Users`
- Camelcase capitalized `MyModel` _NOT_ `myModel`

**Example:**

```prima
model ModelName {
id String @default(uuid()) @id
updated_at DateTime @default(now())
}
```
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ['@commitlint/config-conventional'] };
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
78 changes: 78 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"name": "nodets-bootstrap",
"version": "1.0.0",
"main": "src/index.js",
"repository": "https://github.com/codingwithmanny/nodets-base",
"author": "@codingwithmanny",
"license": "MIT",
"scripts": {
"commit": "git-cz",
"build": "tsc",
"dev": "ts-node-dev src/server.ts",
"start": "export NODE_ENV=production && tsc && node build/server.js",
"test": "yarn test:lint && yarn test:coverage",
"test:jest": "./node_modules/.bin/jest --watch",
"test:coverage": "./node_modules/.bin/jest --coverage",
"test:lint": "./node_modules/.bin/eslint '*/**/*.{js,ts}' --quiet --fix",
"db:save": "./node_modules/.bin/prisma migrate save --experimental",
"db:seed:gen": "cp ./prisma/seedings/TemplateSeeder.ts.example ./prisma/seedings/NEW.ts",
"db:seed:all": "./node_modules/.bin/ts-node-dev ./prisma/seedings/index.ts",
"db:gen": "./node_modules/.bin/prisma generate",
"db:migrate": "./node_modules/.bin/prisma migrate up --experimental",
"db:rollback": "./node_modules/.bin/prisma migrate down --experimental"
},
"dependencies": {
"@prisma/client": "^2.1.3",
"axios": "^0.19.2",
"bcrypt": "^5.0.0",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"csurf": "^1.11.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-validator": "^6.6.0",
"form-data": "^3.0.0",
"helmet": "^3.23.3",
"http-errors": "^1.8.0",
"jsonwebtoken": "^8.5.1",
"jwt-decode": "^2.2.0",
"rand-token": "^1.0.1",
"typescript": "^3.9.6"
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"devDependencies": {
"@commitlint/cli": "^9.0.1",
"@commitlint/config-conventional": "^9.0.1",
"@prisma/cli": "^2.1.3",
"@types/axios": "^0.14.0",
"@types/bcrypt": "^3.0.0",
"@types/cookie-parser": "^1.4.2",
"@types/cors": "^2.8.6",
"@types/csurf": "^1.9.36",
"@types/express": "^4.17.6",
"@types/faker": "^4.1.12",
"@types/helmet": "^0.0.47",
"@types/http-errors": "^1.6.3",
"@types/jest": "^26.0.3",
"@types/jsonwebtoken": "^8.5.0",
"@types/jwt-decode": "^2.2.1",
"@types/node": "^14.0.14",
"@typescript-eslint/eslint-plugin": "^3.5.0",
"@typescript-eslint/parser": "^3.5.0",
"eslint": "^7.3.1",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-jest": "^23.17.1",
"eslint-plugin-prettier": "^3.1.4",
"faker": "^4.1.0",
"husky": "^4.2.5",
"jest": "^26.1.0",
"lint-staged": "^10.2.11",
"prettier": "^2.0.5",
"ts-jest": "^26.1.1",
"ts-node-dev": "^1.0.0-pre.50"
}
}
7 changes: 7 additions & 0 deletions prisma/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#using-environment-variables

# Prisma supports the native connection string format for PostgreSQL, MySQL and SQLite.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"
31 changes: 31 additions & 0 deletions prisma/migrations/20200704130613-init-database/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Migration `20200704130613-init-database`

This migration has been generated by Manny at 7/4/2020, 1:06:13 PM. You can
check out the [state of the schema](./schema.prisma) after the migration.

## Database Steps

```sql

```

## Changes

```diff
diff --git schema.prisma schema.prisma
migration ..20200704130613-init-database
--- datamodel.dml
+++ datamodel.dml
@@ -1,0 +1,11 @@
+// This is your Prisma schema file,
+// learn more about it in the docs: https://pris.ly/d/prisma-schema
+
+datasource db {
+ provider = "postgresql"
+ url = "***"
+}
+
+generator client {
+ provider = "prisma-client-js"
+}
```
Loading

0 comments on commit 9a5bf3d

Please sign in to comment.