Skip to content

Commit

Permalink
try to manage https
Browse files Browse the repository at this point in the history
  • Loading branch information
ozieblo-michal committed Jun 11, 2024
1 parent fe77ed5 commit 911e64a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 32 deletions.
59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ To run the package, you have two options depending on your preference:
- Apply these changes by running `terraform apply`.

`cd terraform/container_db_config && terraform init && terraform plan && terraform apply -auto-approve`

- Use the public IP address in your browser to test the endpoints.
- After you're done, and if you wish to tear down the infrastructure, use `terraform destroy`.

Expand Down Expand Up @@ -133,3 +133,60 @@ The choice between AWS RDS and a containerized Postgres hinges on needs for the
This package is more than an engine. Whether you are a beginner looking to understand the intricacies of AWS services and application deployment, or an experienced developer seeking a quick and reliable solution for your AWS-based projects, this package was crafted to meet your needs.

I welcome contributions, feedback, and inquiries to continually improve and update this repository. Let's build and learn together!










sudo apt-get update
sudo apt-get install nginx -y
sudo mkdir -p /etc/nginx/ssl/
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx-selfsigned.key -out /etc/nginx/ssl/nginx-selfsigned.crt -subj "/CN=<<<IP ADDRESS>>>"
sudo nano /etc/nginx/sites-available/default
sudo systemctl start nginx
sudo systemctl reload nginx


openssl s_client -connect <<<IP ADDRESS>>>






server {
listen 81 ssl;
server_name <<<IP ADDRESS>>>;

ssl_certificate /etc/nginx/ssl/nginx-selfsigned.crt;
ssl_certificate_key /etc/nginx/ssl/nginx-selfsigned.key;

location / {
proxy_pass http://localhost:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

server {
listen 443 ssl;
server_name 52.31.107.76;

ssl_certificate /etc/nginx/ssl/nginx-selfsigned.crt;
ssl_certificate_key /etc/nginx/ssl/nginx-selfsigned.key;

location / {
proxy_pass http://localhost:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
14 changes: 7 additions & 7 deletions src/frontend/my-app/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function App() {
const [fullName, setFullName] = useState('');

// Pobierz URL backendu z zmiennej środowiskowej
const backendUrl = import.meta.env.VITE_BACKEND_URL || 'http://localhost:80';
const backendUrl = import.meta.env.VITE_BACKEND_URL || 'https://localhost:80';

useEffect(() => {
if (token) {
Expand All @@ -28,7 +28,7 @@ function App() {

const fetchDummies = async () => {
try {
const res = await axios.get(`${backendUrl}/dummy`, {
const res = await axios.get(`${backendUrl}/api/dummy`, {
headers: { Authorization: `Bearer ${token}` },
});
console.log('Fetched dummies:', res.data);
Expand All @@ -55,14 +55,14 @@ function App() {
try {
let res;
if (updateMode) {
const url = `${backendUrl}/dummy/${dummyId}`;
const url = `${backendUrl}/api/dummy/${dummyId}`;
console.log('PUT URL:', url);
console.log('PUT dummyId:', dummyId);
res = await axios.put(url, dummyData, {
headers: { Authorization: `Bearer ${token}` },
});
} else {
const url = `${backendUrl}/dummy`;
const url = `${backendUrl}/api/dummy`;
console.log('POST URL:', url);
res = await axios.post(url, dummyData, {
headers: { Authorization: `Bearer ${token}` },
Expand Down Expand Up @@ -93,7 +93,7 @@ function App() {

const handleDelete = async (id) => {
try {
await axios.delete(`${backendUrl}/dummy/${id}`, {
await axios.delete(`${backendUrl}/api/dummy/${id}`, {
headers: { Authorization: `Bearer ${token}` },
});
fetchDummies();
Expand All @@ -105,7 +105,7 @@ function App() {
const handleLogin = async (e) => {
e.preventDefault();
try {
const res = await axios.post(`${backendUrl}/auth/token`, new URLSearchParams({
const res = await axios.post(`${backendUrl}/api/auth/token`, new URLSearchParams({
username,
password,
}));
Expand All @@ -128,7 +128,7 @@ function App() {
console.log('Registering user with data:', userData);

try {
const res = await axios.post(`${backendUrl}/auth/users/`, userData);
const res = await axios.post(`${backendUrl}/api/auth/users/`, userData);
console.log('User registered successfully:', res.data);
setRegisterMode(false);
} catch (err) {
Expand Down
30 changes: 6 additions & 24 deletions src/frontend/my-app/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,7 @@
// import { defineConfig, loadEnv } from 'vite';
// import react from '@vitejs/plugin-react';

// export default defineConfig(({ mode }) => {
// const env = loadEnv(mode, import.meta.env.VITE_MODE || '');

// return {
// plugins: [react()],
// build: {
// outDir: 'dist',
// },
// base: "/vitefast/",
// server: {
// proxy: {
// '/dummy': env.VITE_BACKEND_URL || 'http://localhost:80',
// },
// },
// };
// });



import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig(({ mode }) => {
// Załaduj zmienne środowiskowe na podstawie trybu
const env = loadEnv(mode, process.cwd());

return {
Expand All @@ -35,7 +12,12 @@ export default defineConfig(({ mode }) => {
base: "/vitefast/",
server: {
proxy: {
'/dummy': env.VITE_BACKEND_URL || 'http://localhost:80',
'/api': {
target: env.VITE_BACKEND_URL,
changeOrigin: true,
secure: true,
rewrite: path => path.replace(/^\/api/, ''),
},
},
},
};
Expand Down
8 changes: 8 additions & 0 deletions terraform/container_db_config/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ resource "aws_security_group" "allow_ssh_http" {
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 81
to_port = 81
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}

egress {
from_port = 0
to_port = 0
Expand All @@ -111,6 +118,7 @@ resource "aws_security_group" "allow_ssh_http" {
}



resource "aws_iam_policy" "s3_access_policy" {
name = "S3AccessPolicy"
description = "S3 access policy for EC2 instances"
Expand Down

0 comments on commit 911e64a

Please sign in to comment.