This backend is built using Express and provides a RESTful API for the Portal Berita project. Several routes are protected using JWT tokens for authentication, ensuring secure access to certain endpoints.
- JWT Authentication: Protects routes such as admin, journalist, and user actions.
- Article Management: Allows creation, update, search, and retrieval of articles.
- User Management: Admin can manage user roles and permissions.
-
Clone the repository:
git clone https://github.com/Achmad-Farid/portal-berita-backend.git cd portal-berita-backend
-
Install dependencies:
npm install
-
Start the server:
npm start
-
The API will be available at
http://localhost:5000
.
You can also view the live demo of the API at Portal Berita Backend.
- Admin:
/admin/*
- Journalist:
/journalist/*
- User:
/user/*
POST /signup
: Sign up a new userPOST /login
: Log in and receive a JWT tokenGET /google
: Login via Google OAuthGET /google/callback
: Google OAuth callback
GET /all
: Get all articlesGET /tag
: Get articles by tagGET /detail/:id
: Get article by IDGET /search
: Search articlesGET /popular
: Get popular articlesGET /category/:categoryOrTag
: Get articles by category or tag
GET /articles
: Get articles written by the journalistPOST /articles
: Create a new articlePUT /articles/:id
: Update an existing articleGET /status
: Get under review articlesGET /articles/:id
: Get article by ID
POST /:articleId/bookmark
: Add an article to bookmarksDELETE /:articleId/bookmark
: Remove an article from bookmarksGET /article
: Get bookmarked articlesPOST /:articleId/comments
: Add a comment to an articleGET /:articleId/comments
: Get comments for an articleDELETE /:articleId/comments/:commentId
: Delete a comment
GET /articles
: Get all articlesGET /articles/:id
: Get article by IDPATCH /articles/:articleId/publish
: Publish an articlePATCH /articles/:articleId/unpublish
: Unpublish an articlePATCH /users/:userId/role
: Update user roleDELETE /articles/:id
: Delete an articleGET /search
: Search articlesGET /users
: Get all usersDELETE /users/delete/:userId
: Delete a userPATCH /users/role/:userId
: Update user roleGET /users/role/:role
: Get users by role
- Express for the backend framework
- JWT for authentication
- MongoDB for database (if applicable)