REST API for kollege
Clone the project:
git clone https://github.com/iafthab/kollege_api.git
Change Directory:
cd kollege_api
Install dependencies:
npm install
Create a .env file and paste your MongoDB Database Key (reference video):
DATABASE_URI = mongodb+srv:/username:[email protected]/kollege
// you can give a name of your preference to database instead of kollege
Start the server (node v.19+):
npm run dev
Inside config/corsOptions.js, uncomment "|| !origin" part during development
if (
allowedOrigins.indexOf(origin) !== -1
//! comment out/remove in production
|| !origin
)
Since admin isn't added yet - HOD manages most things.
You'll need to add an HOD manually.
🚀 Use a REST API client like Postman/Thunder Client.
Request Method: POST
Request Address: http://localhost:3500/staff
// the port should be where you host the server, 3500 by default, and not the react port i.e, 3000
Request Body:
{
"name":"...",
"email":"...",
"department":"Computer",
"username":"...",
"password":"...",
"role":"HOD"
}
- ❗Don't forget to fill "..." with necessary details instead of leaving it as it is.
Don't forget to comment out "|| !origin" Inside config/corsOptions.js after development.
if (
allowedOrigins.indexOf(origin) !== -1
//! comment out/remove in production
// || !origin
)
Continue to Kollege Documentation
Go to config/corsOptions.js. Make sure your front-end address is included in allowedOptions:
const allowedOrigins = [
"http://localhost:3000",
// Add the address if you host your front-end somewhere
"https://example.address.com",
];
Errors are bound to happen and the documentation is incomplete.
I'd love to hear feedbacks and suggestions.
In any case, start a conversation: LinkedIn Telegram Mail(Make sure your mail doesn't get flagged as spam/junk)
Thank You ❤️.
- Node,js Tutorial by @gitdagray