Skip to content

Commit

Permalink
added API
Browse files Browse the repository at this point in the history
  • Loading branch information
OlhaDanylevska committed Feb 24, 2024
1 parent 284f0c2 commit 1950dca
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
21 changes: 18 additions & 3 deletions client/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
provider "aws" {
region = "eu-west-2"
access_key = var.access_key
secret_key = var.secret_key
region = "eu-west-2"
access_key = var.access_key
secret_key = var.secret_key
}

# Define variables
Expand Down Expand Up @@ -29,6 +29,21 @@ resource "aws_s3_bucket_public_access_block" "video-app-olha" {
restrict_public_buckets = false
}

resource "aws_s3_bucket_policy" "static_website_policy" {
bucket = aws_s3_bucket.video-app-olha.bucket

policy = jsonencode({
Version = "2012-10-17",
Statement = [{
Sid = "PublicReadGetObject",
Effect = "Allow",
Principal = "*",
Action = "s3:GetObject",
Resource = "${aws_s3_bucket.video-app-olha.arn}/*"
}]
})
}

resource "aws_s3_bucket_acl" "video-app-olha" {
depends_on = [
aws_s3_bucket_ownership_controls.video-app-olha,
Expand Down
4 changes: 2 additions & 2 deletions client/src/Counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Counter = ({ setAllMyVideos, videoId, videoRating }) => {
const handleRatingChange = async (newRating) => {
// PUT request to update the rating in the database
try {
await fetch(`http://ec2-13-43-94-172.eu-west-2.compute.amazonaws.com/videos/${videoId}`, {
await fetch(`http://ec2-13-41-184-74.eu-west-2.compute.amazonaws.com/videos/${videoId}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Expand All @@ -41,7 +41,7 @@ const Counter = ({ setAllMyVideos, videoId, videoRating }) => {
};

const getAllNewVideos = () => {
fetch("http://ec2-13-42-39-111.eu-west-2.compute.amazonaws.com/videos")
fetch("http://ec2-13-41-184-74.eu-west-2.compute.amazonaws.com/videos")
.then(response => {
return response.json()
})
Expand Down
2 changes: 1 addition & 1 deletion client/src/VideoCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ReactPlayer from 'react-player'
const VideoCard = ({ allMyVideos, setAllMyVideos }) => {

const handleDelete = (id) => {
fetch(`http://ec2-13-43-94-172.eu-west-2.compute.amazonaws.com/videos/${id}`, {
fetch(`http://ec2-13-41-184-74.eu-west-2.compute.amazonaws.com/videos/${id}`, {
method: "DELETE"
})
.then((res) => {
Expand Down
8 changes: 8 additions & 0 deletions server/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ resource "aws_security_group" "video_web_sg" {
cidr_blocks = ["${var.my_ip}/32"]
}

ingress {
description = "allow HTTP from my computer"
from_port = 80
to_port = 80
protocol = "HTTP"
cidr_blocks = ["${var.my_ip}/32"]
}

egress {
description = "Allow all outbound traffic"
from_port = 0
Expand Down

0 comments on commit 1950dca

Please sign in to comment.