-
Notifications
You must be signed in to change notification settings - Fork 0
/
readme.txt
143 lines (126 loc) · 5.57 KB
/
readme.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
To run you backend instance just clone realmarketplace_backend on your device from git.
!!required node js 14 or higher!!
- git clone realmarketplace_backend repo
and in the realmerketplace_backed folder run npm install to install all modules.
Modules:
- https://www.npmjs.com/package/mocha
- https://www.npmjs.com/package/chai
- https://www.npmjs.com/package/nyc
- https://www.npmjs.com/package/supertest
- https://www.npmjs.com/package/bcrypt
- https://www.npmjs.com/package/express
- https://www.npmjs.com/package/express-mongo-sanitize
- https://www.npmjs.com/package/multer
- https://www.npmjs.com/package/mongodb
- https://www.npmjs.com/package/urllib
- https://www.npmjs.com/package/uuid
- https://www.npmjs.com/package/typescript
- https://www.npmjs.com/package/body-parser
- https://www.npmjs.com/package/cors
Now to run backend:
- if you want to run backend just type = npm start
- if you want to run tests just type = npm test
Backend configuration file:
- is not included in the code so create one with name = .env (linux ... nano .env)
#connection string use to connect to your mongo db atlas you can generate it in mongo db atlas web application
MONGO_DB_CONNECTION="mongodb+srv://user_name:passowrd@mongo_connection/default_database?retryWrites=true&w=majority"
#name of database that would be used
MONGO_DB_NAME="db_name"
#name of the user collection, place where would all user models be saved
MONGO_USER_COLLECTION="users"
#name of the token collection, place where would all token models be saved
MONGO_TOKEN_COLLECTION="tokens"
#name of the advert collection, place where would all advert models be saved
MONGO_ADVERT_COLLECTION="adverts"
#name of the favorite collection, place where would all favorite models be saved
MONGO_FAVORITE_COLLECTION="favorites"
#mongo project can be found in atlas db project information's
MONGO_PROJECT_ID="project_id"
#cluster name where would be your database with collection you define before
MONGO_CLUSTER_NAME="cluster_name"
#name of the search advert index used to search in adverts by advert title and author
MONGO_SEARCH_INDEX_ADVERT_NAME="advert_search"
#public api key to your mongo db
MONGO_SEARCH_EDITOR_PUBLIC_KEY="public_api_key"
#private api key to your mongo db
MONGO_SEARCH_EDITOR_PRIVATE_KEY="private_api_key"
#port on which would be server listening (default 3000)
PORT=3000
#token expiration time (default 900000)
TOKEN_EXPIRATION_TIME=900000
#temporary password expiration time (default 300000)
USER_RESET_PASSWORD_TIME=300000
#gmail address
GMAIL_ADDRESS="[email protected]"
#gmail app password
EMAIL_PASSWORD="gmail_app_password"
#name of the folder where would be saved all advert images (default public)
FOLDER_IMAGE_PUBLIC = "public"
#name of the folder where would be saved all user profile images (default profile)
FOLDER_IMAGE_PROFILE = "profile"
#name of folder where would be saved all logs (default debug)
FOLDER_LOGS="debug"
#number of adverts that would be returned when searching without query sample (default 4)
NUMBER_IN_SAMPLE=4
#number of adverts that would be returned when searching with query search (default 10)
NUMBER_IN_SEARCH=10
#boolean value that represent if server would (true) or would not (false) response (default false)
PRODUCTION_ENABLE=true
#number fo salt round when encrypting password (default 10)
SALT_ROUNDS=10
If you want to run backend in cloud do these other steps on your virtual machine.
!!all these commands are executed on debian ec2 instance on aws!!
Download ufw firewall end enable 80, 443 ports
- sudo apt install ufw
- sudo ufw enable
- sudo ufw allow ssh
- sudo ufw allow 80
- sudo ufw allow 443
Create instance for realmarketplace backedn deamon:
- sudo nano /etc/systemd/system/realmarketplace.service
Add this configuration into realmarketplace.service:
[Unit]
Description=RealMarketPlace backend deamon
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=2
#WorkingDirectory absolute path to realmarketplace_backend/src cloned folder from github
WorkingDirectory=/home/admin/realmarketplace_backend/src/
#ExecStart absolute path to npm and execute start function to start listing
ExecStart=/usr/bin/npm start
KillMode=process
[Install]
WantedBy=multi-user.target
After saving the configuration of the backend execute this commands to complete configuration of deamon service:
- sudo systemctl daemon-reload
- sudo systemctl enable realmarketplace
- sudo systemctl start realmarketplace
- sudo systemctl status realmarketplace
Install nginx:
- sudo apt install nginx
In nginx configuration file edit this information's:
server 80{
...
#server domain name
server_name realmarketplace.shop www.realmarketplace.shop;
location / {
#in default configuration will server run on port 3000
proxy_pass http://localhost:3000; #whatever port your app runs on
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;
}
...
}
To generate ssl certificate I will be use certbot that use Let’s Encrypt to generate it.
- sudo add-apt-repository ppa:certbot/certbot
- sudo apt-get update
- sudo apt-get install python3-certbot-nginx
- sudo certbot --nginx -d realmarketplace.shop -d www.realmarketplace.shop
# Only valid for 90 days, test the renewal process with
- certbot renew --dry-run