Skip to content

Commit

Permalink
Made frontend and backend talk to eachother
Browse files Browse the repository at this point in the history
  • Loading branch information
Braga Lund committed Nov 28, 2021
1 parent 298762a commit 6704b81
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 2 deletions.
5 changes: 5 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Bragapi

## TODO

* [x] fix cors preflight request locally https://stackoverflow.com/questions/20792950/net-web-api-cors-preflight-request
12 changes: 12 additions & 0 deletions backend/bragapi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
.WithOrigins("http://localhost:8080"));
});

var app = builder.Build();

// Configure the HTTP request pipeline.
Expand All @@ -20,6 +30,8 @@
app.UseSwaggerUI();
}

app.UseCors("CorsPolicy");

app.UseHttpsRedirection();

app.UseAuthorization();
Expand Down
2 changes: 1 addition & 1 deletion backend/bragapi/bragapi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion frontend/braggalot/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<template>
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
<WeatherForecast />
</template>

<script>
import HelloWorld from './components/HelloWorld.vue'
import WeatherForecast from "@/components/WeatherForecast";
export default {
name: 'app',
components: {
HelloWorld
HelloWorld,
WeatherForecast
}
}
Expand Down
37 changes: 37 additions & 0 deletions frontend/braggalot/src/components/WeatherForecast.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<template>
<p>This is the weatherforecasts</p>
<article v-for="forecast in forecasts" :key="forecast.id">
<p>{{ forecast.summary }}</p>
</article>
</template>

<script>
import WeatherForecastApi from "@/services/api/WeatherForecastApi";
export default {
name: 'WeatherForecast',
data() {
return {
loading: true,
forecasts: []
}
},
created() {
WeatherForecastApi.getWeatherForcasts().then(forecasts => {
this.forecasts = forecasts
}).catch(error =>
console.log(error))
.finally(() => {
this.loading = false
}
)
}
}
</script>

<style scoped>
</style>
4 changes: 4 additions & 0 deletions frontend/braggalot/src/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { createApp } from 'vue'
import App from './App.vue'
import axios from 'axios'

axios.defaults.baseURL = 'https://localhost:7189'
axios.defaults.headers.common['Access-Control-Allow-Origin'] = '*';

createApp(App).mount('#app')
14 changes: 14 additions & 0 deletions frontend/braggalot/src/services/api/WeatherForecastApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import axios from 'axios'

export default {
getWeatherForcasts(){
return axios.get('/weatherforecast',{
headers: {

}
})
.then(response => {
return response.data
})
},
}

0 comments on commit 6704b81

Please sign in to comment.