Skip to content

Latest commit

 

History

History
149 lines (102 loc) · 2.73 KB

File metadata and controls

149 lines (102 loc) · 2.73 KB

CarbonFight

Codacy Badge Codacy Badge

CarbonFight is an OpenSource project. This repository contains backend serverless functions.

CalculationsCO2e

"CalculationsCO2e" is an API that allows you to determine the CO2e emissions of a daily action based on the 250 most common CO2e emission factors.

Links

Swagger : API Swagger

Codacy : Codacy

Requirements

Install Nodejs

# On Ubuntu
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - &&\
sudo apt-get install -y nodejs

npm install

Install Firebase CLI

# On Ubuntu
sudo npm install -g firebase-tools
firebase login

Install project dependencies :

# Working directory
cd functions
npm install
npm install express
npm install cors
npm install --save-dev jest
npm install jest supertest express
npm install swagger-ui-express

How to run app WITH firebase emulator

Configure emulator :

cd functions
firebase emulators:start

Execute project :

firebase serve

http://localhost:5000/documentation/#/

How to run app WITHOUT firebase emulator

Uncomment code in functions/index.js from line 24 to 28 to configure the server

const port = 3000;
app.listen(port, () => {
  console.log(`Le serveur écoute sur le port ${port}...`);
});

Run :

npm run local

Access the local Swagger documentation : http://localhost:3000/documentation/#/

How to run Local tests with Jest

npm test 

How to update data

To update data, follow these steps:

Copy the serviceAccountKey.json file into import folder. Run the following command:

cd import
npm install
npm run data

How to deploy in firebase after making changes

Connect to your firebase account and run command :

firebase deploy --only functions --project <nomduprojet>

How to deploy project in a new firebase account

Create firebase account : (https://firebase.google.com/) and connect.

Open terminal :

firebase login

Init the project :

firebase init

Deploy project :

firebase deploy --only functions --project <nomduprojet>