🔧 Fix dev environment
continuous-integration/drone/push Build is passing Details

main
Vincent ASTOLFI 2 months ago
parent 56859467fe
commit c77aacb369

@ -30,10 +30,12 @@ npm install
Now, you have the repo with all the dependency. After that, you'll have to create the database that is used for the account creation and usage.
```
mysql -u user -p
> mysql source db_script.sql
chmod +x ./tools/db_docker_init.sh
./tools/db_docker_init.sh
```
I choose to use container for mysql to avoid bugs that can happened when working on other computers that my main one. It could also fix bug you could face so it's better overall.
Finally, you need a `.env`file with your personnal mysql information so follow those steps. You also need this file to specify your cookie's private key so you can create them
```
@ -43,13 +45,18 @@ touch .env
The .env file should look like that
```
DB_USER=userName
DB_PASSWORD=UserPassword
DB_NAME=maettleship
ACTUAL_ENV=dev
DB_USER=root
DB_PASSWORD=password
DB_NAME=battleship
DB_HOST=localhost
COOKIE_SECRET_KEY=secret_key
```
You can use the env file as it is in my example but if you want make it yours just don't forget to have the same variable in your env file that in you mysql config.
The `ACTUAL_ENV` variable aim to make the switch between dev and prod environment easier. You won't have to change it if you want to run maettleship localy.
Now you can start the server using the following command on your terminal.
`npm run dev`
@ -94,4 +101,4 @@ Here is a cool list of the different docs I used on this project
- [mysql documentation](https://dev.mysql.com/doc/)
- [nodejs documentation](https://nodejs.org/docs/latest/api/)
This project aim to be fully functionnable one day so any recommendation is welcome !
This project aim to be fully functionnable one day so any recommendation is welcome !

@ -3,11 +3,16 @@ const fs = require('node:fs');
try {
const db_user_password = fs.readFileSync(process.env.DB_USER_PASSWORD_FILE, 'utf8').replace(/\r?\n|\r/g, "");
const db_user = fs.readFileSync(process.env.DB_USER_FILE, 'utf8').replace(/\r?\n|\r/g, "");
let db_user = ""
let db_user_password = ""
console.log(db_user)
if (process.env.ACTUAL_ENV === 'dev') {
db_user = process.env.DB_USER
db_user_password = process.env.DB_PASSWORD
} else {
const db_user_password = fs.readFileSync(process.env.DB_USER_PASSWORD_FILE, 'utf8').replace(/\r?\n|\r/g, "");
const db_user = fs.readFileSync(process.env.DB_USER_FILE, 'utf8').replace(/\r?\n|\r/g, "");
}
const connection = mysql.createPool({
host: process.env.DB_HOST,

@ -40,7 +40,7 @@ app.get('/error', (req, res) => {
app.post('/logIn', (req, res) => {
const { pseudo, password } = req.body;
if (!pseudo || !password) {
return res.status(400).send('pseudo and password are required.');
}

@ -0,0 +1,12 @@
#!/bin/sh
# Use it to create mysql container so you don't have to make it run locally
# Run it from the root directory
docker stop mysql-maettleship
docker remove mysql-maettleship
docker run --name mysql-maettleship -d -p 3306:3306 \
-e MYSQL_ROOT_PASSWORD='password' \
-e MYSQL_USER='vinz' \
-e MYSQL_PASSWORS='1234' \
-v ./db:/docker-entrypoint-initdb.d mysql
Loading…
Cancel
Save