Frontend Repository: BlogAdmin
MyBlog_Backend is an Express.js API that powers a blog platform. It provides endpoints for authentication, content management, comment functionality, and administrative tasks.
- Authentication System - Secure user authentication with Passport.js
- Content Management - Full CRUD operations for blog posts
- Comment System - Support for user comments on blog content
- Admin Dashboard API - Endpoints for administrative functions
- CORS Support - Configured security for frontend applications
- Node.js - JavaScript runtime
- Express - Web application framework
- Passport.js - Authentication middleware
- PostgreSQL - Database
- dotenv - Environment variable management
- CORS - Cross-Origin Resource Sharing support
- Node.js (v14.x or higher)
- npm or yarn
- MongoDB (local instance or Atlas)
- Clone the repository
git clone https://github.com/Giolii/MyBlog_Backend.git
cd MyBlog_Backend
- Install dependencies
npm install
# or
yarn install
- Set up environment variables
# Create a .env file in the root directory
touch .env
Add the required environment variables:
DATABASE_URL="postgresql://gi:Postpsw@localhost:5432/test_db"
SESSION_SECRET
ACCESS_KEY_ID
SECRET_ACCESS_KEY
PORT
SUPABASE_URL
SUPABASE_KEY
SUPABASE_SERVICE_KEY
JWT_SECRET
- Start the development server
npm run dev
# or
yarn dev
- The API will be available at
http://localhost:8080
POST /auth/register
- Register a new userPOST /auth/login
- Log in a userGET /auth/profile
- Get user profile (protected)
GET /posts
- Get all blog postsGET /posts/:id
- Get a specific postPOST /posts
- Create a new post (protected)PUT /posts/:id
- Update a post (protected)DELETE /posts/:id
- Delete a post (protected)
GET /comments/post/:postId
- Get comments for a postPOST /comments
- Add a comment (protected)PUT /comments/:id
- Update a comment (protected)DELETE /comments/:id
- Delete a comment (protected)
GET /admin/dashboard
- Get admin dashboard data (protected)GET /admin/users
- Get all users (protected/admin)PUT /admin/users/:id
- Update user roles (protected/admin)
This API uses Passport.js with JWT strategy for authentication. Protected routes require a valid JWT token in the Authorization header:
Authorization: Bearer <token>
The API is configured to accept requests from the following origins:
- Your primary frontend URL (from VITE_FRONTEND_URL)
- Your secondary frontend URL (from VITE_FRONTEND_URL2)
# Set NODE_ENV to production in your .env file
NODE_ENV=production
The API can be deployed on various platforms including:
- Heroku
- Digital Ocean
- AWS (EC2, Elastic Beanstalk)
- Railway
- Render
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Thank you!