Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarpanchal committed Aug 30, 2020
0 parents commit a48225b
Show file tree
Hide file tree
Showing 90 changed files with 13,780 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_size = 2
indent_style = space
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
env: {
es6: true,
node: true,
jest: true,
},
extends: 'eslint:recommended',
parserOptions: {
ecmaVersion: 2020,
},
rules: {
'no-console': 1,
'no-unused-vars': 1,
},
}
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
npm-debug.log

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*

# System Files
.DS_Store
Thumbs.db

# misc
/.keys
/.logs
/.uploads

# config
/config/*
!/config/default.js
!/config/config.test.js
.env

# public
/public/*
!/public/.gitkeep
7 changes: 7 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
printWidth: 120,
semi: false,
singleQuote: true,
tabWidth: 2,
useTabs: false,
}
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"EditorConfig.EditorConfig",
"esbenp.prettier-vscode"
]
}
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/index.js",
// "envFile": "${workspaceFolder}/.env",
"env": {
"NODE_PATH": ".",
"NODE_ENV": "development",
"DEBUG": "*",
"INIT": "0"
},
"args": ["--use-strict"],
"outputCapture": "std"
}
]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Sagar Panchal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
105 changes: 105 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
## 🚀 Getting Started

### 📋 Prerequisites

- node >= v10.16.3
- mongodb >= v4.2
- ~~redis-server >= v4.0.9 (for socket.io and cacheing)~~
- ~~wsl (only required on windows to run redis-server)~~

### 🔧 Installing

#### Clone this repo

```bash
git clone <repo_url>

cd ./<project_directory>
```

#### Create and switch to directory to store keys

```bash
mkdir -p ./.keys && cd ./.keys
```

#### Generate RSA keys for JWT

<small>On windows use git-bash or wsl</small>

```bash
# Generate RSA256 certificate
ssh-keygen -t rsa -b 2048 -m PEM -f jwt_rsa.key

# Convert RSA256 public key to certificate
openssl rsa -in jwt_rsa.key -pubout -outform PEM -out jwt_rsa.key.pub
```

#### Go back to project root

```bash
cd ..
```

#### Install all dependencies

```bash
npm i
```

> List of dependencies can be found in `package.json`
#### Configuration

> For config, see [`Additional Configuration`](./config.md)
#### Debugging

- Debugging config for visual studio code is already included Press `F5` to start debugging

#### Logging

- By default, run-time exceptions will be logged to `./.logs/<NODE_ENV>/<YYYY>-<MM>/<YYYY>-<MM>-<DD>.json`

> To change logging to database see [`Additional Configuration`](./config.md)
### 📦 FrontEnd

- Build and place your frontend files in `/public` directory
- All HTTP GET requests not matching with `^\/api*` will be redirected to `/public/index.html`

### ⚙️ Running

```bash
npm start # runs `npm run dev`
npm run dev # runs in development mode
npm run prod # runs in production mode
npm run prod-stop # stops in production mode
npm run prod-monit # `pm2 monit` in production
```

> If you're using windows, please ensure that redis-server is running inside wsl before you run any of these commands > `wsl sudo service redis-server restart`
> Production mode uses [`pm2`](https://github.com/Unitech/pm2/blob/master/README.md) cluster-mode for load-balancing
> See `scripts` in `package.json`
### 🛠️ Development

#### Testing

```bash
npm run test
```

#### Linting

```bash
npm run lint .
```

#### ESLint plugins for vscode

```bash
code --install-extension dbaeumer.vscode-eslint
```
23 changes: 23 additions & 0 deletions api-docs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const package = require('package')
const paths = require('./paths')

module.exports = {
openapi: '3.0.1',
info: {
title: package.name,
contact: { email: '[email protected]' },
version: package.version,
},
servers: [{ url: 'https://localhost/api' }],
tags: [{ name: 'Authentication' }],
paths,
components: {
securitySchemes: {
BearerToken: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
},
},
},
}
5 changes: 5 additions & 0 deletions api-docs/paths/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
// ...require('./auth'),
// ...require('./user'),
...require('./media'),
}
61 changes: 61 additions & 0 deletions api-docs/paths/media/file.post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"/media/file": {
"post": {
"summary": "Upload file",
"description": "Upload file and get file metadata",
"tags": ["Media"],
"security": [{ "BearerToken": [] }],
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"required": [],
"type": "object",
"properties": {
"file": {
"type": "string",
"format": "binary"
}
}
}
}
},
"required": true
},
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"originalname": {
"type": "string"
},
"encoding": {
"type": "string"
},
"mimetype": {
"type": "string"
},
"acl": {
"type": "string"
},
"key": {
"type": "string"
},
"location": {
"type": "string"
},
"etag": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
61 changes: 61 additions & 0 deletions api-docs/paths/media/image.post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"/media/image": {
"post": {
"summary": "Upload image",
"description": "Upload image and get image metadata",
"tags": ["Media"],
"security": [{ "BearerToken": [] }],
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"required": [],
"type": "object",
"properties": {
"image": {
"type": "string",
"format": "binary"
}
}
}
}
},
"required": true
},
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"originalname": {
"type": "string"
},
"encoding": {
"type": "string"
},
"mimetype": {
"type": "string"
},
"acl": {
"type": "string"
},
"key": {
"type": "string"
},
"location": {
"type": "string"
},
"etag": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
Loading

0 comments on commit a48225b

Please sign in to comment.