Skip to content

Commit

Permalink
1. Adds team api
Browse files Browse the repository at this point in the history
2. Fixex JS public assets
  • Loading branch information
butschster committed Apr 21, 2024
1 parent b2e32e1 commit d707f89
Show file tree
Hide file tree
Showing 30 changed files with 221 additions and 55 deletions.
38 changes: 38 additions & 0 deletions .docker/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

server {
server_name _;

location /connection {
proxy_pass http:https://buggregator-ws:8089/connection;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
}

location /example/call {
proxy_pass http:https://buggregator-examples:8000;
proxy_set_header Host $http_host;
}

location /github {
proxy_pass http:https://buggregator-api:8000;
proxy_set_header Host $http_host;
}

location /api {
proxy_pass http:https://buggregator-api:8000;
proxy_set_header Host $http_host;
}

location / {
proxy_pass http:https://buggregator-spa:3000;
proxy_set_header Host $http_host;
}

listen 80;
}
2 changes: 1 addition & 1 deletion app/app/src/Application/Bootloader/GithubBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function defineSingletons(): array

WebhookGate::class => static fn(
EnvironmentInterface $env,
) => new WebhookGate(secret: $env->get('GITHUB_WEBHOOK_SECRET', 'secret')),
) => new WebhookGate(secret: $env->get('GITHUB_WEBHOOK_SECRET')),
];
}
}
3 changes: 2 additions & 1 deletion app/app/src/Endpoint/Http/Controller/GithubWebhookAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Github\WebhookGate;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Http\Message\ResponseInterface;
use Spiral\Http\Exception\ClientException\ForbiddenException;
use Spiral\Http\Request\InputManager;
use Spiral\Http\ResponseWrapper;
use Spiral\Router\Annotation\Route;
Expand All @@ -29,7 +30,7 @@ public function __invoke(
ClientInterface $client,
): ResponseInterface {
if (!$gate->validate((string)$input->request()->getBody(), $input->header('x-hub-signature-256'))) {
// throw new ForbiddenException('Invalid signature');
throw new ForbiddenException('Invalid signature');
}

$event = match ($input->header('x-github-event')) {
Expand Down
38 changes: 38 additions & 0 deletions app/app/src/Endpoint/Http/Controller/TeamAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace App\Endpoint\Http\Controller;

use App\Application\Http\Response\ResourceInterface;
use App\Endpoint\Http\Resource\TeamCollection;
use App\Endpoint\Http\Resource\TeamResource;
use Spiral\Router\Annotation\Route;

final readonly class TeamAction
{
#[Route(route: 'team', name: 'team', methods: ['GET'], group: 'api')]
public function __invoke(): ResourceInterface
{
return new TeamCollection([
[
'name' => 'Pavel Buchnev',
'role' => 'Creator of Buggregator',
'avatar' => 'https://avatars.githubusercontent.com/u/773481?v=4',
'github' => 'https://github.com/butschster',
],
[
'name' => 'Aleksei Gagarin',
'role' => 'PHP developer',
'avatar' => 'https://avatars.githubusercontent.com/u/4152481?v=4',
'github' => 'https://github.com/roxblnfk',
],
[
'name' => 'Andrey Kuchuk',
'role' => 'Frontend developer',
'avatar' => 'https://avatars.githubusercontent.com/u/13301570?v=4',
'github' => 'https://github.com/Kreezag',
],
], TeamResource::class);
}
}
12 changes: 12 additions & 0 deletions app/app/src/Endpoint/Http/Resource/TeamCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace App\Endpoint\Http\Resource;

use App\Application\Http\Response\ResourceCollection;

final class TeamCollection extends ResourceCollection
{

}
12 changes: 12 additions & 0 deletions app/app/src/Endpoint/Http/Resource/TeamResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace App\Endpoint\Http\Resource;

use App\Application\Http\Response\JsonResource;

final class TeamResource extends JsonResource
{

}
6 changes: 5 additions & 1 deletion app/app/src/Github/WebhookGate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
final readonly class WebhookGate
{
public function __construct(
private string $secret,
private ?string $secret = null,
) {
}

public function validate(string $payload, string $signature): bool
{
if (!$this->secret) {
return true;
}

return \hash_equals(
\hash_hmac('sha256', $payload, $this->secret),
\substr($signature, 7),
Expand Down
44 changes: 22 additions & 22 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ services:
context: ./
dockerfile: ./.docker/app/Dockerfile
environment:
# TOKENIZER_CACHE_TARGETS: true
APP_ENV: production
DEBUG: false
VERBOSITY_LEVEL: basic
Expand All @@ -48,11 +49,8 @@ services:

RR_CENTRIFUGE_PROXY_ADDRESS: tcp:https://0.0.0.0:10001
RR_CENTRIFUGE_GRPC_API_ADDRESS: tcp:https://buggregator-ws:10000
labels:
- "traefik.enable=true"
- "traefik.http.routers.buggregator-api-http.entrypoints=web"
- "traefik.http.routers.buggregator-api-http.rule=Host(`api.buggregator.localhost`)"
- "traefik.http.services.buggregator-api-http.loadbalancer.server.port=8000"

GITHUB_WEBHOOK_SECRET: ${GITHUB_WEBHOOK_SECRET:-null}
volumes:
- ./app:/app
depends_on:
Expand All @@ -64,13 +62,12 @@ services:
build:
context: ./
dockerfile: ./.docker/spa/Dockerfile
labels:
- "traefik.enable=true"
- "traefik.http.routers.buggregator-spa-http.entrypoints=web"
- "traefik.http.routers.buggregator-spa-http.rule=Host(`buggregator.localhost`)"
- "traefik.http.services.buggregator-spa-http.loadbalancer.server.port=3000"
# volumes:
# - ./spa:/app
environment:
NUXT_PUBLIC_API_URL: http:https://buggregator.localhost
NUXT_PUBLIC_WS_URL: ws:https://buggregator.localhost/connection/websocket
NUXT_PUBLIC_EXAMPLES_URL: http:https://buggregator.localhost
# volumes:
# - ./spa:/app
networks:
- buggregator-network

Expand All @@ -79,11 +76,6 @@ services:
volumes:
- ./.docker/centrifugo/config.json:/centrifugo/config.json
command: centrifugo -c config.json
labels:
- "traefik.enable=true"
- "traefik.http.routers.buggregator-ws-http.entrypoints=web"
- "traefik.http.routers.buggregator-ws-http.rule=Host(`ws.buggregator.localhost`)"
- "traefik.http.services.buggregator-ws-http.loadbalancer.server.port=8089"
depends_on:
- buggregator-api
networks:
Expand Down Expand Up @@ -119,11 +111,6 @@ services:
INSPECTOR_API_KEY: test
BUGGREGATOR_URL: ${BUGGREGATOR_DEMO_URL:-http:https://demo.buggregator.localhost}
PROFILER_ENDPOINT: http:https://profiler@buggregator-demo:8000
labels:
- "traefik.enable=true"
- "traefik.http.routers.buggregator-examples-http.entrypoints=web"
- "traefik.http.routers.buggregator-examples-http.rule=Host(`examples.buggregator.localhost`)"
- "traefik.http.services.buggregator-examples-http.loadbalancer.server.port=8000"
depends_on:
- buggregator-pgsql
networks:
Expand Down Expand Up @@ -196,6 +183,19 @@ services:
networks:
- buggregator-network

buggregator-nginx:
image: nginx
restart: always
volumes:
- ./.docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
labels:
- "traefik.enable=true"
- "traefik.http.routers.buggregator-http.entrypoints=web"
- "traefik.http.routers.buggregator-http.rule=Host(`buggregator.localhost`)"
- "traefik.http.services.buggregator-http.loadbalancer.server.port=80"
networks:
- buggregator-network

networks:
buggregator-network:
ipam:
Expand Down
12 changes: 11 additions & 1 deletion spa/app/api/Api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import apiMethods from '~/app/api/methods';
import { RPCClient } from "~/app/ws/RPCClient";
import { SettingsResponse } from "~/config/types";
import { SettingsResponse, TeamMember } from "~/config/types";

type SettingsApi = {
get: () => SettingsResponse,
Expand All @@ -10,6 +10,10 @@ type ExamplesApi = {
call: (action: string) => void,
}

type TeamApi = {
list: () => TeamMember[],
}

export default class Api {
private readonly rpc: RPCClient;
private readonly _api_url: string;
Expand All @@ -27,6 +31,12 @@ export default class Api {
}
}

get team(): TeamApi {
return {
list: apiMethods.team(this.rpc),
}
}

get examples(): ExamplesApi {
return {
call: apiMethods.callExampleAction(this._examples_url),
Expand Down
7 changes: 6 additions & 1 deletion spa/app/api/methods.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import {
SettingsResponse,
TeamResponse,
ServerResponse
} from "~/config/types";
import { RPCClient } from "~/app/ws/RPCClient";

const settings = (rpc: RPCClient) => () => rpc.call('get:api/settings')
.then((response: ServerResponse<SettingsResponse>) => response.data);

const team = (rpc: RPCClient) => () => rpc.call('get:api/team')
.then((response: ServerResponse<TeamResponse>) => response.data.data);

const callExampleAction = (host: string) => (action: string) => {
action = action.toLowerCase();

const path: string = action === 'profiler:report' ? '_profiler' : '';
const path: string = action === 'profiler:report' ? 'example/call/profiler' : 'example/call';

return useFetch(`${host}/${path}`, {
method: 'POST',
Expand All @@ -23,5 +27,6 @@ const callExampleAction = (host: string) => (action: string) => {

export default {
settings,
team,
callExampleAction
}
10 changes: 7 additions & 3 deletions spa/components/v1/GithubStars.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { useAppStore } from "~/stores/app";
import AnimatedCounter from 'vue-animated-counter';
import JSConfetti from 'js-confetti';
type Props = {
repository: number;
Expand All @@ -11,14 +11,18 @@ const props = withDefaults(defineProps<Props>(), {
size: 'md',
});
const jsConfetti = new JSConfetti();
const stars = computed(() => {
const app = useAppStore();
return app.github[props.repository].stars;
}, {
onTrigger(e) {
if (e.key === 'stars') {
console.log('Stars updated');
jsConfetti.addConfetti({
emojis: ['🦄', '', '🎉', '💖', '🚀', '😍'],
emojiSize: 50,
confettiNumber: 40,
});
}
}
});
Expand Down
48 changes: 28 additions & 20 deletions spa/components/v1/Team.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
<script setup lang="ts">
import GridRow from "~/components/v1/GridRow.vue";
import { useTeamStore } from "~/stores/team";
const users = [
{
name: 'Pavel Buchnev',
role: 'Creator of Buggregator',
avatar: 'https://avatars.githubusercontent.com/u/773481?v=4',
github: 'https://github.com/butschster'
},
{
name: 'Aleksei Gagarin',
role: 'PHP developer',
avatar: 'https://avatars.githubusercontent.com/u/4152481?v=4',
github: 'https://github.com/roxblnfk'
},
{
name: 'Andrey Kuchuk',
role: 'Frontend developer',
avatar: 'https://avatars.githubusercontent.com/u/13301570?v=4',
github: 'https://github.com/Kreezag'
},
]
const store = useTeamStore();
await store.fetch();
const users = computed(() => {
return store.team;
});
// const users = [
// {
// name: 'Pavel Buchnev',
// role: 'Creator of Buggregator',
// avatar: 'https://avatars.githubusercontent.com/u/773481?v=4',
// github: 'https://github.com/butschster'
// },
// {
// name: 'Aleksei Gagarin',
// role: 'PHP developer',
// avatar: 'https://avatars.githubusercontent.com/u/4152481?v=4',
// github: 'https://github.com/roxblnfk'
// },
// {
// name: 'Andrey Kuchuk',
// role: 'Frontend developer',
// avatar: 'https://avatars.githubusercontent.com/u/13301570?v=4',
// github: 'https://github.com/Kreezag'
// },
// ]
</script>

<template>
Expand Down
11 changes: 11 additions & 0 deletions spa/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ export interface SettingsResponse {
}
}

export interface TeamMember {
name: string;
role: string;
avatar: string;
github: string;
}

export interface TeamResponse {
data: TeamMember[];
}

export interface ServerResponse<T> {
data: T;
response: {
Expand Down
Loading

0 comments on commit d707f89

Please sign in to comment.