Logo Lanfrica

FaizaInaAbdirizak48/Somalia-Natural-Resources-Management

Domaine:

environment and energy

Type de record:

software
Créateur:
Fai
Hôte:
# SNRMS Backend (Spring Boot + PostgreSQL) This is the backend for the Somalia Natural Resources Management System. It was built by reading your React frontend's code (pages + services) and matching its exact API expectations — so no frontend changes were needed except two small integration wires (see bottom of this file). ## 1. Prerequisites - Java 17+ (`java -version`) - Maven (or use the wrapper if you add one) — `mvn -version` - PostgreSQL running locally, with a database created: ```sql CREATE DATABASE snrms_db; ``` ## 2. Configure the database connection Open `src/main/resources/application.yml` and update these three lines if your Postgres username/password differ from the defaults: ```yaml spring: datasource: url: jdbc:postgresql://localhost:5432/snrms_db username: postgres password: postgres ``` ## 3. Run the backend ```bash cd backend mvn spring-boot:run ``` On first run you'll see this in the console: ``` No users found - created a default admin account: username: admin password: Admin@123 ``` Hibernate will also auto-create all the tables for you (`ddl-auto: update`). The API is now live at `localhost`. ## 4. Run the frontend Two tiny changes were made to your frontend so it talks to this backend instead of the placeholder ASP.NET one: - `vite.config.js` — the dev proxy now points `/api` at `localhost` instead of `localhost`. - `src/services/api.js` — added an axios interceptor that attaches `Authorization: Bearer ` to every request, reading the token from `localStorage`. - `src/context/AuthContext.jsx` — saves the token to `localStorage` on login, clears it on logout. Nothing else changed. Run the frontend as usual: ```bash npm install npm run dev ``` Log in with `admin` / `Admin@123`. ## 5. How security works here - `GET` requests on Categories/Resources/Projects/Reports are **public** (no login needed) — because your public pages (Home, PublicProjects, PublicResearch, PublicGISMap) call th …