Angular is better than Somfony
benoit-bremaud / angular-social-network Goto Github PK
View Code? Open in Web Editor NEWAngular is better than Somfony
License: MIT License
Angular is better than Somfony
License: MIT License
Écrivez des tests unitaires pour les composants Angular.
Description : Create scripts for deploying the backend and frontend to hosting services.
Steps :
Description
Create a release branch to prepare for a new production release.
Steps
development
branch and pull the latest changes:git checkout development
git pull origin development
git checkout -b release/vX.X.X
git push origin release/vX.X.X
production
and development
.Criteria for Success
A new release branch is created and pushed to the remote repository.
Pull requests are opened for merging the release branch into production
and development
.
Description
Automate the deployment of the frontend to Netlify using GitHub Actions.
Steps
deploy-frontend.yml
) to .github/workflows
:
name: Deploy Frontend
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Build frontend
run: npm run build
- name: Deploy to Netlify
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
run: |
npm install netlify-cli -g
netlify deploy --prod --dir=dist --site=<your-netlify-site-id>
Criteria for Success
The frontend is automatically deployed to Netlify on every push to the main
branch.
main
Description
Configure branch protection rules for the main
branch to ensure stability and prevent accidental changes.
Steps
main
.
- - Enable "Require approvals" and set the number of approvals required.
- - Enable "Dismiss stale pull request approvals when new commits are pushed".
Criteria for Success
main
branch has the protection rules enabled and configured as specified.Description
Create a template for pull requests to ensure consistency and completeness in code reviews.
Steps
.github/PULL_REQUEST_TEMPLATE/
.pull_request_template.md
):
**Description**
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes # (issue)
**Type of change**
Please delete options that are not relevant.
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
**How Has This Been Tested?**
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.
- [ ] Test A
- [ ] Test B
**Checklist:**
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules
Criteria for Success
The directory .github/PULL_REQUEST_TEMPLATE/ exists in the repository.
A template for pull requests is created and pushed to the repository.
ranch Naming Convention (Refer to BRANCH_NAMING_GUIDE.md):
Use meaningful branch names like feature/xyz, bugfix/abc, release/v1.0.0.
Example:
bash
Copy code
git checkout -b feature/setup-project-structure
Description : Set up a local MongoDB instance and create a database for the project.
Steps :
Description : Define a User model using Mongoose with fields for username, email, and password.
Steps :
Description
Create templates for reporting bugs and requesting features to ensure consistency and completeness in issue reporting.
Steps
.github/ISSUE_TEMPLATE/
.bug_report.md
):
---
name: Bug report
about: Create a report to help us improve
title: "[BUG]"
labels: bug
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.
feature_request.md
):name: Feature request
about: Suggest an idea for this project
title: "[FEATURE]"
labels: enhancement
assignees: ''
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
Describe the solution you'd like
A clear and concise description of what you want to happen.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
Criteria for Success
The directory .github/ISSUE_TEMPLATE/ exists in the repository.
Templates for bug reports and feature requests are created and pushed to the repository.
Description : Create a login form for existing users.
Steps :
development
Description
Configure branch protection rules for the development
branch to ensure stability and prevent accidental changes.
Steps
development
.
- - Enable "Require approvals" and set the number of approvals required.
- - Enable "Dismiss stale pull request approvals when new commits are pushed".
Criteria for Success
development
branch has the protection rules enabled and configured as specified.Description
Create a hotfix branch to fix critical bugs in production.
Steps
production
branch and pull the latest changes:git checkout production
git pull origin production
git checkout -b hotfix/bug-description
git add .
git commit -m "Fix bug-description"
git push origin hotfix/bug-description
production
and development
.Criteria for Success
A new hotfix branch is created and pushed to the remote repository.
Pull requests are opened for merging the hotfix branch into production
and development
.
Commit Message Guidelines (Refer to COMMIT_NAMING_GUIDE.md):
Use clear and concise commit messages.
Example:
git add .
git commit -m "feat(structure): initial project setup with backend and frontend directories"
Description
Create the initial branches for the project: main
, development
, and production
.
Steps
main
branch:git checkout -b main
git push origin main
development
branch:git checkout -b development
git push origin development
production
branch:git checkout -b production
git push origin production
Criteria for Success
The main
, development
, and production
branches are created and pushed to the remote repository.
Description
Add detailed documentation for branch protection rules and workflow procedures in the README file.
Steps
README.md
file in your code editor.Criteria for Success
README.md
file contains a detailed section on branch management and workflow procedures.Description : Implement an authentication service to handle user registration and login.
Steps :
Description : Create a registration form for new users.
Steps :
Sure, let's create the issue for setting up the .env
file. This issue will help us securely manage environment variables and sensitive information.
.env
for Environment VariablesSet up environment variables using a .env
file to securely manage sensitive information like JWT secrets, database connection strings, etc.
dotenv
package..env
file..env
file by adding it to .gitignore
.Create a new branch for this feature:
git checkout main
git checkout -b feature/setup-env
dotenv
PackageInstall the dotenv
package to manage environment variables:
cd backend
npm install dotenv
.env
FileCreate a .env
file in the root of your backend
directory:
touch .env
Add your environment variables to the .env
file. For example:
JWT_SECRET=your_jwt_secret
MONGODB_URI=mongodb://localhost:27017/angular-social-network
Update your app.js
and other relevant files to load environment variables using dotenv
.
Update backend/app.js
import express from 'express';
import mongoose from 'mongoose';
import dotenv from 'dotenv';
import authRoutes from './routes/auth.js';
import authMiddleware from './middleware/authMiddleware.js';
import Post from './models/Post.js';
dotenv.config();
const app = express();
const port = 3000;
app.use(express.json());
// Connect to MongoDB
mongoose.connect(process.env.MONGODB_URI).then(() => {
console.log('Connected to MongoDB');
}).catch(err => {
console.error('Error connecting to MongoDB', err);
});
// Use authentication routes
app.use('/api/auth', authRoutes);
// Protected route example
app.post('/api/posts', authMiddleware, async (req, res) => {
const { title, content, author } = req.body;
try {
const post = new Post({ title, content, author });
await post.save();
res.status(201).send(post);
} catch (error) {
res.status(400).send('Error creating post');
}
});
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});
Update auth.js
to use the JWT secret from the environment variables:
Update backend/routes/auth.js
import express from 'express';
import bcrypt from 'bcrypt';
import jwt from 'jsonwebtoken';
import User from '../models/User.js';
const router = express.Router();
// Register route
router.post('/register', async (req, res) => {
const { username, email, password } = req.body;
try {
const hashedPassword = await bcrypt.hash(password, 10);
const user = new User({ username, email, password: hashedPassword });
await user.save();
res.status(201).send(user);
} catch (error) {
res.status(400).send('Error registering user');
}
});
// Login route
router.post('/login', async (req, res) => {
const { email, password } = req.body;
try {
const user = await User.findOne({ email });
if (!user) {
return res.status(404).send('User not found');
}
const isPasswordValid = await bcrypt.compare(password, user.password);
if (!isPasswordValid) {
return res.status(401).send('Invalid password');
}
const token = jwt.sign({ id: user._id }, process.env.JWT_SECRET, { expiresIn: '1h' });
res.json({ token });
} catch (error) {
res.status(400).send('Error logging in');
}
});
export default router;
.env
FileAdd the .env
file to your .gitignore
to prevent it from being committed to your repository:
echo ".env" >> .gitignore
Add the modified files and commit following Angular commit message conventions:
git add .
git commit -m "chore: setup environment variables using .env
- Install dotenv package
- Create .env file for environment variables
- Update application to use environment variables
- Secure .env file by adding it to .gitignore"
Push your changes to the remote repository:
git push -u origin feature/setup-env
main
as the base and feature/setup-env
as the compare branch.Example Title and Description for the Pull Request:
Title: "chore: setup environment variables using .env"
Description:
### Description
- Install dotenv package
- Create .env file for environment variables
- Update application to use environment variables
- Secure .env file by adding it to .gitignore
### Checklist
- [x] Environment variables configured
- [x] Application updated to use environment variables
- [x] .env file secured in .gitignore
feature/setup-env
branch after merging.main
Branchgit checkout main
git pull origin main
You have now set up environment variables using a .env
file to securely manage sensitive information like JWT secrets and database connection strings. You also created a pull request for this feature and followed an organized and collaborative workflow.
If you have any questions or need assistance with the next steps, feel free to let me know!
Description
Automate tests and integrations using GitHub Actions for continuous integration and continuous deployment (CI/CD).
Steps
1. Create a .github/workflows
directory in the repository.
2. Add a YAML file for the CI workflow (ci.yml
).
3. Configure the workflow to run tests and checks on every push and pull request:
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
Criteria for Success
Description
Automate the deployment of the backend to Heroku using GitHub Actions.
Steps
deploy-backend.yml
) to .github/workflows
:
name: Deploy Backend
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install dependencies
run: npm install
- name: Deploy to Heroku
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
run: |
git remote add heroku https://git.heroku.com/<your-heroku-app-name>.git
git push heroku main
Criteria for Success
The backend is automatically deployed to Heroku on every push to the main branch.
Description : Initialize a new Node.js project, install Express.js, and set up a basic Express server.
Steps :
npm init -y
npm install express
app.js
and set up a basic serverCriteria for Success : The server runs on http://localhost:5000 and displays "Hello World" when accessing the root route.
Description : Define a Post model using Mongoose with fields for author, content, and timestamps.
Steps :
Description
Create a new branch for developing a specific feature.
Steps
development
branch and pull the latest changes:git checkout development
git pull origin development
git checkout -b feature/your-feature-name
git add .
git commit -m "Add your-feature-name"
git push origin feature/your-feature-name
development
Criteria for Success
A new feature branch is created and pushed to the remote repository.
A pull request is opened for merging the feature branch into development.
Description : Write unit tests to ensure the User model behaves as expected.
Steps :
Step-by-Step Guide to Deploy Backend on Plesk
Prerequisites
- Install bcrypt for password hashing and jsonwebtoken for JWT handling:
cd backend npm install bcrypt jsonwebtoken
Originally posted by @benoit-bremaud in #5
backend git:(feature/auth-routes) npm install bcrypt jsonwebtoken
npm warn deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm warn deprecated [email protected]: This package is no longer supported.
npm warn deprecated [email protected]: This package is no longer supported.
npm warn deprecated [email protected]: This package is no longer supported.
added 69 packages, removed 17 packages, changed 3 packages, and audited 137 packages in 55s
The warnings you received are related to deprecated packages used by bcrypt and jsonwebtoken dependencies. These warnings are common and do not usually affect the functionality of your application immediately. However, it's always good to keep your dependencies up to date to avoid potential issues in the future.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.