-
Create an account at https://cloud.mongodb.com/
-
Create User.
-
Click 'Quickstart', scroll down, and check whether any IP address exists.
If there is no IP address, click 'Add My Current IP Address'.
Next time, if you see this in 'Overview':
click 'Add Current IP Address'
-
Click 'CONNECT' in 'Overview' (First of the left sidebar):
-
Choose 'Compass' as your access data tool, then copy the connection string.
-
Download 'Compass'.
-
Open MongoDB Compass.
-
Paste the connection string into the 'URI', and replace with the password for the user.
-
Click 'Save & Connect'. (If you have a problem here, visit https://www.mongodb.com/community/forums/t/error-while-connecting-my-database-through-mongodb-compass/243317)
-
Create a database. -- (Remember the database's name)
- Download and install IntelliJ IDEA Community Edition at https://www.jetbrains.com/idea/download/?section=windows
- Download this voting system and open it as a project in IntelliJ IDEA.
-
Go to the
voting\src\main\resources
folder, and build a new.env
document. -
Rewrite this
.env
document as.env.example
. -
Add real values with
" "
after every "=
".To fill out the
MONGO_DATABASE
, copy the database's name and paste it here.To fill out the
MONGO_CLUSTER
, copy the string behind@
in the connection string we copied before.MONGO_USER
andMONGO_PASSWORD
are your account user's name and password.For example:
MONGO_DATABASE="abc-voting" MONGO_USER="abc" MONGO_PASSWORD="abc" MONGO_CLUSTER="cluster0.edplh85.mongodb.net"
-
Open 'VotingApplication.java' in
voting\src\main\java\com\example\voting
folder and run (Shift+F10
).Or you can run system by using
mvn spring-boot:run
. (instead of step 4) -
Open 'Terminal' (tap
Alt+F12
). -
Go to the 'frontend' folder (
cd frontend
) -
Start the system (
npm start
)
Before creating a delegate
and logger
, stop running 'VotingApplication.java'
For creating delegate
, use mvn spring-boot:run "-Dspring-boot.run.arguments=--create-delegate"
under the 'voting' folder.
-
After CLI stop running, you can set
delegate's name
(Username
hidden before), thenEnter
. -
Set
password
, thenEnter
. -
Set
Email
, thenEnter
.(You can use this email and password to log in as a delegate)
For example:
-
Then type another command to create a
logger
asdelegate
's process:mvn spring-boot:run "-Dspring-boot.run.arguments=--create-logger"
System Requirements of the Server:
- JDK 21
- Node.js 14+
- MongoDB Compass
- Nginx
-
For deploying the system, use
mvn clean package
under the 'voting' folder. -
For deploying the frontend, use
npm run build
under the 'frontend' folder. -
Copy the
voting-0.0.1-SNAPSHOT.jar
file fromvoting\target
folder to the server. -
Copy the
build
folder fromfrontend
folder to the server. -
run
npm install -g serve
before you runserve -s build
under thebuild
folder. -
run
java -jar voting-0.0.1-SNAPSHOT.jar
under the folder where thevoting-0.0.1-SNAPSHOT.jar
file is located. -
Open Nginx configuration file and add the following code:
-
If you want to use HTTP, you can use the following code:
server { listen 80; server_name example.com; location / { proxy_pass http://localhost:3000; } location /api { proxy_pass http://localhost:8080; } }
-
If you want to use HTTPS, you need to install a certificate. You can use Let's Encrypt to get a free certificate. use the following code:
server { listen 80; server_name example.com; listen 443 ssl; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_protocols TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_session_timeout 5m; location / { proxy_pass http://localhost:3000; } location /api { proxy_pass http://localhost:8080; } }
-
-
-
Restart Nginx.
-
If you want to use HTTP, you can simply visit
http://[server-ip]
. If you want to use HTTPS, you can visithttps://[hostname-assciated-to-ssl-certificate]
.
- Frontend Application Fails to Start:
Ensure that Node.js is correctly installed. Run
npm install
in the frontend folder to install all necessary frontend dependencies. - Backend Application Fails to Start:
Ensure that the MongoDB database service is running. Verify that the network connection is stable and not blocked by a firewall. Ensure that the database connection information in the
.env
file is accurate and correct. - Java 1.8 and 11 does not support Spring Framework 6+. If you get the error
class file has wrong version 61.0, should be 55.0
when you run VotingApplication.java, you should downgrade your Spring Framework to 5.3.x and check your Java version. For more information, visit https://stackoverflow.com/questions/74648576/spring-class-file-has-wrong-version-61-0-should-be-55-0. - This uses JDK 21 as Development Environment. So that JDK 21 is strongly recommended.