This is the iScsc website source code. This website is still under development
The tech stack I chose for this web application is MERN with:
- MongoDB for the database
- Express for the API
- React for the frontend
- Node.js for the backend
For more information, check this article. You can also watch this video if you want to get more familiar with the stack. If you're a true beginner, you can follow this Open Classroom course.
- Functionalities
- Deployment
2.1 Setup the local MongoDB folder
2.2 Development mode
2.3 Production mode - Repository structure
- Bugs and recommendations
- Upcoming work
1. Functionalities (toc)
The main functionalities of the website at the moment are creating, reading, and deleting posts on the blog section of the website. Posts are rendered in Markdown, with the Github Flavored Markdown, GFM. The authentication is now available. A user can sign up and log in with an email and a password. Some actions in the blog, like creating and deleting articles, need authentication. JWT and cookies allow the user to stay logged in.
You should be able to create your post in the /create-article route. Creating a post requires authentication.
Two writing options are available:
- Writing the post directly inside the form inputs
- Submitting a markdown file
For the first option, no editor is available at the moment on the website, so writing a post directly from the Textarea field might be harsh. That is why the second way is recommended. A template is available for the markdown file submission.
When creating a post, a preview is available on the right side of your browser. The author assigned to the article will be the name of the authenticated user.
Any article submitted by other users can be read through the /blog route.
You should be able to delete any article you created from the database.
Note: if you try to delete an article you did not write, it won't work but you won't receive any error message.
2. Deployment (toc)
You need to setup 3 things to run the website:
.env.*
file- MongoDB host folder
- start frontend, backend and database
For deployment, development
and production
modes are available
Send me a message, and I'll send you back an encrypted version of the official
.env.production
and.env.development
files.
Here is a quick guide after cloning the repository:
2.1 Setup the local MongoDB folder (toc)
To make the database persistent through containers starting and stopping the database folder is shared with the host using a docker
volume, you can see it in the docker compose files.
β οΈ β οΈ IMPORTANT: the following script will give rwx permissions on the DB folder to the UID 1001 due to bitnami/mongodb image constraint (the Note under "Persisting your database"), if, on your systemn, it already exists and shouldn't have these access please consider modifying the image!
However because the bitnami/mongodb container is a non-root container we've got to setup the right permission on that folder.
To set it up just run
./scripts/setup-db-folder.sh
2.2 Development mode (toc)
You have two choices to run the development mode:
Before deploying the application, you need to set the environment variables.
From the root directory of the repository, do the following:
cp .env.example .env.development
After copying the example config of .env
, you must fill in the missing information in this file. Check the example for more information.
Once your .env.development
is ready, run
docker-compose --env-file .env.development --file docker-compose-dev.yml up -d --build
Make sure the
docker
daemon is running withsystemctl status docker
, or start it withsystemctl start docker
The website is now up on $CLIENT_URL
(specified in the .env.development
file)
To see the running application, and check the logs use
docker ps
docker logs <CONTAINER_ID>
Finally, you can stop it with
docker-compose --env-file .env.development --file docker-compose-dev.yml down
From the root directory of the repository, do the following:
cd backend
npm install
npm run dev
You will need
nodemon
to run the backend. Usenpm install -g nodemon
to install it. Make sure you're supporting at least 2.0.20 withnodemon --version
. Nodemon has been tested working fine with node 19.
From the root directory of the repository, do the following:
cd frontend
npm install
npm run start
Make sure you're using at least version 8.19.2 by checking npm --version
, and update if needed with npm update
.
Start a MongoDB either in a container and expose a port or directly on your host with the right port configured. Then setup properly the .env, it should work but this is untested.
2.3 Production mode (toc)
The production mode allows to deploy the application on the server. To use it, you will need:
docker
docker-compose
Before deploying the application, you need to set the environment variables as for development
mode.
cp .env.example .env.production
To set up HTTPS, you will need valid SSL certificates. If you deploy the app for the first time, follow these instructions:
- Comment or delete the whole server section about 443 in the
nginx/nginx.conf.template
file.
- server {
- listen 443 default_server ssl http2;
- ...
- }
This step is required because the certificates don't exist yet, so they cannot be loaded in the nginx configuration.
- (Re)Start the
nginx
container:
sudo docker-compose --env-file .env.production up -d --build
- Create the certificates with the
certbot
container:
sudo docker-compose --env-file .env.production run --rm certbot certonly --webroot --webroot-path /var/www/certbot/ -d yourdomainname.com
- Restore the original
nginx/nginx.conf.template
(withgit restore nginx/nginx.conf.template
for example) - Stop the
nginx
container:
sudo docker-compose --env-file .env.production down
The certificates should have been generated in certbot/conf/live/yourdomainname.com/
If you just want to renew existing certificates, use:
sudo docker-compose --env-file .env.production run --rm certbot renew
Once everything is ready, run
sudo docker-compose --env-file .env.production up -d --build
Make sure the
docker
daemon is running withsystemctl status docker
, or start it withsystemctl start docker
Your application can now be started on $CLIENT_URL
(specified in the .env.production
file)
To see the running application, and check the logs, use
sudo docker ps
sudo docker logs <CONTAINER_ID>
Finally, you can stop the production mode with
sudo docker-compose --env-file .env.production down
3. Repository structure (toc)
Here is a list of the main folders/files of the repository.
iscsc.fr
β
βββ .env.development *stores database credentials and required information for development mode deployment. Must be created*
βββ .env.production *Same thing for production mode. Must be created*
βββ .env.example *template for .env files*
β
βββ backend *contains the server-side code and API*
β βββ Dockerfile *Dockerfile to build the backend container*
β βββ controllers/ *useful js functions for each model*
β βββ middleware/ *js functions that run between the frontend and backend*
β βββ models/ *contains the database models*
β βββ routes/ *routes and functions to executes for each model*
β βββ app.js *main application for the backend*
β
βββ frontend
β βββ public *automatically generated files and images that are publically available for the user*
β βββ Dockerfile *Dockerfile to build the frontend container*
β βββ src *source code of the website*
β βββ components/ *source code of main components of the website*
β βββ context/ *defines the context function to keep track of data with useReducer*
β βββ hooks/ *defines the hooks that trigger the context functions*
β βββ pages/ *source code of the pages of the website*
β βββ App.js *defines the routes of the application*
β βββ index.js *main js application of the website*
β βββ index.css *css styling file of the website*
βββ scripts
β βββ gpg-share.sh *share a secret file to others with pgp keys*
β
βββ nginx *reverse proxy server for the production mode*
β βββ Dockerfile *Dockerfile to build the nginx container*
β βββ run_nginx.sh *script to generate the nginx conf from the template*
β βββ nginx.conf.template *template for the nginx conf, needs to be filled with env variables*
β
βββ bump.sh *script used to bump version of frontend, backend, and whole website*
βββ docker-compose.yml *docker compose config file to deploy the website in production mode*
βββ package.json *contains the current version and information about the website*
βββ README.md *this file*
4. Bugs and recommendations (toc)
Because this website is still in development, do not hesitate to open an issue if you experience any trouble using it. Also, feel free to share your recommendations regarding the color scheme, routes, design, UX, etc...
5. Upcoming work (toc)
Here is a non-exhaustive list of incoming functionalities for the website:
- User profile, with article management
- Likes and comments
- Main page
- Calendar
- News and events
- Pictures, avatars for users
- Search bar
- Gallery with previous works, events
- Videos integration
- ...