Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ _ReSharper*/
### .NET / ASP.NET Core
# Keep base appsettings.json in repo; ignore local/env-specific
appsettings.Development.json
.env

# DP keys Api
docker/dpkeys/*.xml
Expand Down
13 changes: 13 additions & 0 deletions backend/PromoCodeFactory.WebHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,26 @@

builder.Services.AddOpenApi(builder.Environment);

builder.Services.AddCors(options =>
{
options.AddPolicy("Frontend", policy =>
{
policy
.WithOrigins("http://app.test.me:5173")
.AllowAnyHeader()
.AllowAnyMethod();
});
});

var app = builder.Build();

app.UseExceptionHandler();

app.MapOpenApi();
app.MapSwaggerUI();

app.UseCors("Frontend");

app.MapControllers();

app.MigrateDatabase();
Expand Down
16 changes: 8 additions & 8 deletions backend/PromoCodeFactory.WebHost/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"profiles": {
"PromoCodeFactory.WebHost": {
"commandName": "Project",
"launchUrl": "swagger",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:8090;http://localhost:8091",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
"commandName": "Project",
"launchUrl": "swagger",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://api.test.me:8090;http://api.test.me:8091",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
1 change: 1 addition & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_API_BASE_URL=http://api.test.me:8091
5 changes: 5 additions & 0 deletions frontend/src/common/http.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;

export async function apiFetch(path: string, init?: RequestInit) {
return fetch(`${API_BASE_URL}${path}`, init);
}
3 changes: 2 additions & 1 deletion frontend/src/components/private/PartnerLimits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { UiState } from "../../common/types";
import { PartnerSchema, type PartnerDto } from "../public/zodType";
import { ResultBlock } from "../common/ResultBlock";
import { SuccessResultPartnerLimit } from "./SuccessResultPartnerLimit";
import { apiFetch } from "../../common/http";

export function PartnerLimits() {
const partnerId = useAppSelector(state => state.demoIdentity.partnerId);
Expand All @@ -22,7 +23,7 @@ export function PartnerLimits() {
}

const url = `/api/v1/partners/${encodeURIComponent(partnerId)}`;
const response = await fetch(url);
const response = await apiFetch(url);

await sleep(500);

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/private/PartnerProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { UiState } from "../../common/types";
import { PartnerSchema, type PartnerDto } from "../public/zodType";
import { ResultBlock } from "../common/ResultBlock";
import { SuccessResultPartnerProfile } from "./SuccessResultPartnerProfile";
import { apiFetch } from "../../common/http";

export function PartnerProfile() {
const partnerId = useAppSelector(state => state.demoIdentity.partnerId);
Expand All @@ -22,7 +23,7 @@ export function PartnerProfile() {
}

const url = `/api/v1/partners/${encodeURIComponent(partnerId)}`;
const response = await fetch(url);
const response = await apiFetch(url);

await sleep(500);

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/public/FetchApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Title,Text, Stack, Button } from "@mantine/core";
import { sleep } from "../../common/tools";
import type { UiState } from "../../common/types";
import { SuccessResultCustomer, } from "./SuccessResultCustomer";
import { apiFetch } from "../../common/http";

const idGood = "a3f767aa-1918-4b0d-a3c9-37e5a0e5f3b2";
const idBad = "a3f767aa-1918-4b0d-a3c9-37e5a0e5f3b3";
Expand All @@ -16,7 +17,7 @@ export function FetchApi() {
setUiState({ kind: "loading" });
try {
const urlGetCustomerById = `/api/v1/customers/${encodeURIComponent(id)}`;
const response = await fetch(urlGetCustomerById);
const response = await apiFetch(urlGetCustomerById);
await sleep(500);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
Expand Down
2 changes: 2 additions & 0 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const target = process.env.API_URL || 'http://localhost:8091';
export default defineConfig({
plugins: [react()],
server: {
host: "app.test.me",
port: 5173,
proxy: {
'/api': {
target,
Expand Down