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

Add fully functioning server #4

Open
wants to merge 106 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
5c7180e
[.env.example] Rearrange and add SENDGRID_API_KEY to .env.example
BharathKumarRavichandran Jun 18, 2019
8bb2885
Refactor: Remove and rename redunctant instiVerificationCode to verti…
BharathKumarRavichandran Jun 18, 2019
833ad97
Refactor: Rename/Normalize student auth email routes
BharathKumarRavichandran Jun 18, 2019
6a4cd86
Feat: Add util function to send password reset email
BharathKumarRavichandran Jun 18, 2019
4ec8dd4
Feat: Add controllers for password forgot and reset routes
BharathKumarRavichandran Jun 18, 2019
83e1bb0
Feat: Add validator for .edu email
BharathKumarRavichandran Jun 18, 2019
70a83e9
Remove instiVerificationCode from form submission check
BharathKumarRavichandran Jun 18, 2019
0dee939
[storage] Add directories logs and uploads
BharathKumarRavichandran Jun 18, 2019
31de6a5
[package] Add util to package to promisify callbacks
BharathKumarRavichandran Jun 21, 2019
1f3e59d
[config] Add new keys - directory and import path
BharathKumarRavichandran Jun 21, 2019
b7a88a8
Refactor: Normalize all routes to follow some standard convention
BharathKumarRavichandran Jun 21, 2019
0483a22
[deadline.middleware] Fix unhandled promise rejection errors
BharathKumarRavichandran Jun 21, 2019
ab5db74
Feat: Add helper class for handling single and multiple file uploads
BharathKumarRavichandran Jun 21, 2019
1e1afe6
[controllers] Add file upload handling for all controllers
BharathKumarRavichandran Jun 21, 2019
f2eac0b
Append directory path uploads/ to uploaded files
BharathKumarRavichandran Jun 21, 2019
a7fc59e
Refactor: Change filename storing logic to include randomstring
BharathKumarRavichandran Jun 21, 2019
11c8bcf
[package] Add mkdirp to create student directories
BharathKumarRavichandran Jun 21, 2019
d24edc6
Move uploads directory to public folder
BharathKumarRavichandran Jun 21, 2019
36f4fd3
Refactor: Add dev and prod UPLOADS_DIR keys and refactor keys
BharathKumarRavichandran Jun 21, 2019
0d5753f
Feat: Initialize model and create student directory
BharathKumarRavichandran Jun 21, 2019
49505af
Feat: Add good password check rule to register controller
BharathKumarRavichandran Jun 21, 2019
afeade8
Refactor: Change files uploads to doclinks in mentor essays controller
BharathKumarRavichandran Jun 23, 2019
78490bf
Add basic production-ready docker configuration
BharathKumarRavichandran Jun 23, 2019
58ab5d7
Configure docker-compose.yml
BharathKumarRavichandran Jun 23, 2019
8f0425e
Feat: Add util function to mail application summary
BharathKumarRavichandran Jun 24, 2019
c47aba7
[package] Add archiver, ejs, easy-pdf-merge, kue, kue-ui to package
BharathKumarRavichandran Jun 26, 2019
5fb7367
[.env] Configure ports for APP and kue
BharathKumarRavichandran Jun 26, 2019
f9d9808
[config] Add google_auth tokens, dir, configure ports
BharathKumarRavichandran Jun 26, 2019
e99f03e
Refactor: Minor changes in return statements
BharathKumarRavichandran Jun 26, 2019
0525eba
[env/gitignore] Add google auth tokens
BharathKumarRavichandran Jun 26, 2019
e8d1430
Feat: Add utility functions to archive applications
BharathKumarRavichandran Jun 26, 2019
ac3c2ad
Feat: Add utility function to send application archive to student
BharathKumarRavichandran Jun 26, 2019
83ea655
Feat: Add keys to store archives, application path
BharathKumarRavichandran Jun 26, 2019
0328e0a
Feat: Initialize kue job queues
BharathKumarRavichandran Jun 26, 2019
7965545
Feat: Add workers for archive,mail and upload jobs
BharathKumarRavichandran Jun 26, 2019
11b6eb6
[package] Add wkhtmltopdf and remove html-pdf
BharathKumarRavichandran Jun 26, 2019
181c18b
Feat: Add utility functions to generate and merge pdfs
BharathKumarRavichandran Jun 26, 2019
9d52d27
Feat: Add ejs template for personal-info pdf generation
BharathKumarRavichandran Jun 26, 2019
16fefcf
Feat: Add controllers to view and submit form
BharathKumarRavichandran Jun 26, 2019
7d9de6a
Refactor: Rename PORT to APP_PORT in application server file
BharathKumarRavichandran Jun 26, 2019
79ed503
Refactor: Standardize api response from all controllers and functions
BharathKumarRavichandran Jun 26, 2019
33e01f9
[package] Add morgan and winston logger to package
BharathKumarRavichandran Jun 27, 2019
cb3dc39
[.env] Add variable 'environment'
BharathKumarRavichandran Jun 27, 2019
eb6fc64
Feat: Add winston logging configuration
BharathKumarRavichandran Jun 27, 2019
262c373
Feat: Add loggers to all controllers, middlewares and utils
BharathKumarRavichandran Jun 27, 2019
6e0b697
Feat: Add more personal information fields
BharathKumarRavichandran Jun 28, 2019
93f8644
Fix: Made wkhtmltopdf async and add file existance check
BharathKumarRavichandran Jun 28, 2019
10b7b04
[package]: Add delay
BharathKumarRavichandran Jun 28, 2019
f40c5ae
Styles: Add Montserrat font styles ttf files
BharathKumarRavichandran Jun 28, 2019
e21a57a
Feat: Style and align personal information pdf rendering
BharathKumarRavichandran Jun 28, 2019
7caf7a1
Feat: Add feature to upload files to google drive
BharathKumarRavichandran Jun 29, 2019
30c9616
Remove debug console.logs
BharathKumarRavichandran Jun 29, 2019
e70a072
Add SENDGRID_API_KEY and configure public path for static files
BharathKumarRavichandran Jun 29, 2019
81bd5d8
Fix: Add required variable to google drive upload worker
BharathKumarRavichandran Jun 29, 2019
25a5d18
[README] Update README.md with installation instructions
BharathKumarRavichandran Jun 29, 2019
aaae74e
Fix: Correct deadline middleware to include time
BharathKumarRavichandran Jun 29, 2019
ae6078b
[.gitignore] Add .vscode and logs
BharathKumarRavichandran Jul 2, 2019
b4bf3cd
Add shell script to start servers and workers
BharathKumarRavichandran Jul 2, 2019
fdf8183
[Docker] Add redis image and configure docker files
BharathKumarRavichandran Jul 2, 2019
06b863b
Change request methods to include standard conventions
BharathKumarRavichandran Jul 10, 2019
67c19fb
Fix: Change body params to query for GET HTTP method
BharathKumarRavichandran Jul 15, 2019
e62c4fb
Feat: Add routes to get form access and application number
BharathKumarRavichandran Jul 15, 2019
06075e7
Fix: Change default values for optional enum fields
BharathKumarRavichandran Jul 15, 2019
821d5e2
Refactor: Modify send controller to handle resend verification routes
BharathKumarRavichandran Jul 15, 2019
3230b22
Feat: Create mailing jobs on submission of mentors URL
BharathKumarRavichandran Jul 16, 2019
74e3cdb
Feat: Add worker to process mailMentor jobs
BharathKumarRavichandran Jul 16, 2019
f504f90
Feat: Add utility function to mail mentors
BharathKumarRavichandran Jul 16, 2019
b5719c7
Feat: Add utility function to create mailing jobs on hitting controller
BharathKumarRavichandran Jul 16, 2019
4131374
Add sample mentors data as a json file
BharathKumarRavichandran Jul 16, 2019
5309082
[gitignore] Add config/mentorsList.json to .gitignore
BharathKumarRavichandran Jul 16, 2019
cfe0133
Feat: Add utility function to get pending requirements
BharathKumarRavichandran Jul 16, 2019
0973724
[README] Update README to include mentorsList details
BharathKumarRavichandran Jul 16, 2019
5b4b31d
[package] Add http-status-codes
BharathKumarRavichandran Jul 16, 2019
ceaca71
[controllers] Refactor: Standardize all response status codes
BharathKumarRavichandran Jul 16, 2019
03657a7
[utils] Refactor: Standardize all response status codes
BharathKumarRavichandran Jul 16, 2019
7f5fceb
[dockerignore] Ignore example files
BharathKumarRavichandran Jul 16, 2019
de28690
Feat: Add route to verify frontend session
BharathKumarRavichandran Jul 18, 2019
d9ea766
Feat: Add session's maxAge after it is set
BharathKumarRavichandran Jul 18, 2019
6ba1abd
Fix: Debug error in workers
BharathKumarRavichandran Jul 19, 2019
b3c8fee
Breaking refactor: Make changes for production
BharathKumarRavichandran Jul 19, 2019
5fff592
[env.example] Add docker env instructions
BharathKumarRavichandran Jul 19, 2019
83f6b19
Update node_app_entry script
BharathKumarRavichandran Jul 19, 2019
564f971
Update nginx configuration for production serve
BharathKumarRavichandran Jul 19, 2019
a2241d7
Fix: Change all pending requirements response format
BharathKumarRavichandran Aug 22, 2019
babfdb2
Change file uploads directory to frontend public directory
BharathKumarRavichandran Aug 23, 2019
595e838
Add path of uploaded files to response
BharathKumarRavichandran Aug 23, 2019
3f07b26
Build(deps): Bump lodash from 4.17.11 to 4.17.15
dependabot[bot] Aug 23, 2019
57fc03b
Merge pull request #1 from BharathKumarRavichandran/dependabot/npm_an…
BharathKumarRavichandran Aug 23, 2019
33d7e52
Edit success response message for sendToMentors controllers
BharathKumarRavichandran Aug 24, 2019
8fd205d
Fix: MongooseError bug in form submission
BharathKumarRavichandran Aug 24, 2019
bad5d20
Change backend static-files path
BharathKumarRavichandran Aug 24, 2019
f4c29d2
Fix: Debug boolean envs by comparing strings
BharathKumarRavichandran Aug 24, 2019
29aeb44
[.env] Add MAINTENANCE env variable
BharathKumarRavichandran Aug 24, 2019
758b270
Build(deps): Bump eslint-utils from 1.3.1 to 1.4.2
dependabot[bot] Aug 27, 2019
ddf248b
Build(deps): Bump mixin-deep from 1.3.1 to 1.3.2
dependabot[bot] Aug 31, 2019
504b721
[docker] Add vim, wkhtmltopdf and modify volume mapping
BharathKumarRavichandran Sep 14, 2019
f41d8d9
Fix: Undefined error in supporting-files upload
BharathKumarRavichandran Sep 14, 2019
03f9f43
[scripts] Add linux packages installation to a separate file
BharathKumarRavichandran Sep 16, 2019
57228a5
[docker] Add scripts and setup xvfb
BharathKumarRavichandran Sep 16, 2019
bc00814
Feat: Add controllers for form view and access
BharathKumarRavichandran Sep 16, 2019
65a32d6
Feat: Add authentication to Mongo docker image
BharathKumarRavichandran Sep 17, 2019
929b36a
Feat: Add database authentication and remove CORS_ORIGIN env var
BharathKumarRavichandran Sep 17, 2019
a5f77c5
Fix: Variable usage errors and debug env settings
BharathKumarRavichandran Sep 17, 2019
f6029d0
Fix indentation
BharathKumarRavichandran Sep 17, 2019
b7f4df5
Feat: Add more special characters to password RegEx
BharathKumarRavichandran Sep 18, 2019
40c04c1
[scripts] Add script to clear docker mounted data and logs
BharathKumarRavichandran Sep 18, 2019
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
24 changes: 24 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
node_modules

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
npm-debug.log

Dockerfile*
.docker-compose*
.dockerignore

.git
.gitignore

.env.example
*.example.json

*.md
!README.md
LICENSE
.vscode
35 changes: 27 additions & 8 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
API_URL=http://localhost:8000
CLIENT_URL=http://localhost:3000
CORS_ORIGIN=http://localhost:3000
APP_SECRET=something_secret
SESSION_SECRET=something_secret

# Provide service_name for DB_HOST while running in docker, otherwise use localhost
DB_HOST=localhost
# Provide exposed docker port while running in docker, otherwise use 27017
DB_PORT=27017
# DB_AUTH_ENABLED (true or false)
DB_AUTH_ENABLED=false
DB_AUTH_SOURCE=admin
DB_NAME=JSPF
DB_USERNAME=db_username
DB_PASSWORD=db_password
DB_URI=mongodb://localhost/JSPF

PORT=8000
# Provide service_name to REDIS_HOST(redis) while running in docker
# While running in normal mode, provide host (localhost)
REDIS_HOST=redis
REDIS_PORT=6379

APP_PORT=8000
KUE_PORT=5000
DEBUG=true
MAINTENANCE=false
environment=development

SENDGRID_API_KEY=

API_BASE_URL=http://localhost:8000
CLIENT_BASE_URL=http://localhost:3000

APP_SECRET=something secret
SESSION_SECRET=something secret
BASE_DIR=
CLIENT_BASE_DIR=

[email protected]
START_DATE=// dd-mm-yyyy
END_DATE=// dd-mm-yyyy
START_DATE_JS=// mm-dd-yyyy
END_DATE_JS=// mm-dd-yyyy
START_YEAR=// yyyy
END_YEAR=// yyyy
END_YEAR=// yyyy
18 changes: 17 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

*.out

docker/data/*

.vscode/
node_modules/
.env
.env
google_auth_credentials.json
google_auth_token.json
google_auth_service_jwt.json
mentorsList.json
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,36 @@
# JSPF-Server
Backend for Jitheshraj Scholarship Portal Form.
Backend for Jitheshraj Scholarship Portal Form.

### Prerequisites
* Install [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)
* Install [MongoDB](https://docs.mongodb.com/manual/administration/install-community/)
* Install [redis](https://redis.io/) :
```
sudo apt-get install redis-server
```

### Project Installation
1. Clone the repository - `git clone <remote-url>`
2. Go to the project directory - `cd <cloned-repo>`
3. Install dependencies - `npm install`
4. Copy contents of `.env.example` to a new file `.env`
* Configure `PORT`, `environment` and `SECRET` variables
* Set `DB_USERNAME`, `DB_PASSWORD` and `DB_URI` to your localhost mongodb credentials
* Get and set `SENDGRID_API_KEY` to access application mailing routes
* `API_BASE_URL = 'http://localhost:8000'`
* `CLIENT_BASE_URL = 'http://localhost:3000'`
* Set `BASE_DIR` and `CLIENT_BASE_DIR` to your appropriate directories path to configure file uploads.
* Set the `DATE` and `YEAR` variables in their respective formats. You won't be able to access certain routes without this.
5. Copy contents of `src/config/google_auth_credentials.example.json` to a new file `src/config/google_auth_credentials.json` and set all the parameters and configure accordingly in Google developer console to give Google Drive API upload/write access.
6. Copy contents of `src/config/mentorsList.example.json` to a new file `src/config/mentorsList.json` and add all the mentors details.
7. Start `MongoDB` service - `sudo service mongod start`
8. Start application and kue server - `node index`
9. Open a new terminal and start kue workers - `node /src/workers`
10. Instead, to start both servers and workers - `./run_server.sh`
11. Access kue API and dashboard from http://localhost at its configured _port_ number. Or at http://localhost:5000/api and http://localhost:5000/kue respectively, by default.
12. Install _JSPF-Web_ if needed, from [BharathKumarRavichandran/JSPF-Web](https://github.com/BharathKumarRavichandran/JSPF-Web)

#### Troubleshooting
* If you face some version incompatability issues while installing/running, check your `node` and `npm` versions and ensure it is compatible with the project. (Tip: Use nvm :p)
* If you face any mongo error, check whether `MongoDB` service (_mongod_ daemon) is running.
* If you're unable to generate PDFs, make sure your [wkhtmltopdf](https://www.npmjs.com/package/wkhtmltopdf) rendering engine(_QT_) path is configured properly.
38 changes: 38 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: '3'

services:

redis:
image: redis:3.0-alpine
container_name: jspf-redis
command: redis-server
volumes:
- './docker/data/redis:/data'
ports:
- "6379:6379"

mongodb:
image: 'mongo'
container_name: jspf-mongo
env_file:
- './docker/mongo/.env'
volumes:
- './docker/data/mongodb:/data/db'
ports:
- '27017:27017'

node_app:
build:
context: ./
dockerfile: ./docker/build_files/Dockerfile
container_name: jspf-server
restart: always
volumes:
- ./storage/logs:/usr/src/app/storage/logs
- ../JSPF-Web/public/uploads:/usr/src/app/public/uploads
ports:
- '5000:5000'
- '8000:8000'
depends_on:
- mongodb
- redis
20 changes: 20 additions & 0 deletions docker/build_files/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:8-alpine

WORKDIR /usr/src/app

COPY ./scripts ./scripts
RUN ./scripts/install_packages.sh

RUN Xvfb :1 -screen 0 800x600x24&
RUN Xvfb :99 -ac &

ENV NODE_ENV=production

COPY ./package*.json ./
RUN npm install --only=production
COPY . ./

EXPOSE 5000
EXPOSE 8000

CMD ["./scripts/node_app_entry.sh"]
2 changes: 2 additions & 0 deletions docker/mongo/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MONGO_INITDB_ROOT_USERNAME=root
MONGO_INITDB_ROOT_PASSWORD=rootPassXXX
32 changes: 32 additions & 0 deletions docker/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
server {

listen 80;
server_name form.jrscholarship.org;

access_log /var/log/nginx/access.log;

# listen 443 ssl;

# ssl_certificate /etc/nginx/conf.d/nginx.crt;
# ssl_certificate_key /etc/nginx/conf.d/nginx.key;

location / {
proxy_set_header Host $host;
proxy_pass http://0.0.0.0:3000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

location /api {
proxy_set_header Host $host;
proxy_pass http://0.0.0.0:8000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
require('./src/server').start()
// Start app server
require('./src/server.js').start();

// Start kue server
require('./src/kue.server.js').start();
Loading