fixed cors added prometheus

This commit is contained in:
SwiftyOS
2024-09-12 18:35:11 +02:00
parent b9c26b1a6b
commit 30e3d65711
5 changed files with 53 additions and 5 deletions

View File

@@ -46,7 +46,7 @@ export default class MarketplaceAPI {
pageSize: number = 10,
): Promise<AgentListResponse> {
return this._get(
`/top-downloads/agents?page=${page}&page_size=${pageSize}`,
`agents/top-downloads?page=${page}&page_size=${pageSize}`,
);
}
@@ -54,7 +54,7 @@ export default class MarketplaceAPI {
page: number = 1,
pageSize: number = 10,
): Promise<AgentListResponse> {
return this._get(`/featured/agents?page=${page}&page_size=${pageSize}`);
return this._get(`/agents/featured?page=${page}&page_size=${pageSize}`);
}
async searchAgents(

View File

@@ -1,5 +1,5 @@
ServerAddress: ":8015"
DatabaseURL: "postgresql://agpt_user:pass123@localhost:5432/agpt_local?connect_timeout=60"
DatabaseURL: "postgresql://agpt_user:pass123@localhost:5432/agpt_marketplace?connect_timeout=60"
JWTSecret: "Z86RsQ+nhSk+A8ODJX1kQA11JCk9nlw8n+MRdSgmR+P1sMPTTDG1rjBTwj7Ucjb3TRHSVxkCNPgXISmzU/vMkA=="
JWTAlgorithm: "HS256"
CORSAllowOrigins:

View File

@@ -13,4 +13,35 @@ services:
ports:
- "5432:5432"
market:
build:
context: .
dockerfile: Dockerfile
ports:
- "8015:8015"
depends_on:
postgres:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8015/metrics"]
interval: 30s
timeout: 10s
retries: 3
prometheus:
image: prom/prometheus:latest
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- "9090:9090"
depends_on:
- market
grafana:
image: grafana/grafana:latest
ports:
- "9091:3000"
depends_on:
- prometheus

View File

@@ -58,6 +58,9 @@ func main() {
} else {
corsConfig.AllowOrigins = []string{"*"} // Fallback to allow all origins if not specified
}
corsConfig.AllowHeaders = append(corsConfig.AllowHeaders, "Authorization")
corsConfig.AllowMethods = []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}
corsConfig.AllowCredentials = true
r.Use(cors.New(corsConfig))
// Route welcome
@@ -67,7 +70,10 @@ func main() {
// Setup routes
api := r.Group("/api")
// [Error] Request header field Authorization is not allowed by Access-Control-Allow-Headers.
// [Error] Fetch API cannot load http://localhost:8015/api/v1/market/featured/agents?page=1&page_size=10 due to access control checks.
// [Error] Failed to load resource: Request header field Authorization is not allowed by Access-Control-Allow-Headers. (agents, line 0)
api := r.Group("/api/v1/market/")
{
agents := api.Group("/agents")

11
rnd/gosrv/prometheus.yml Normal file
View File

@@ -0,0 +1,11 @@
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'market'
static_configs:
- targets: ['market:8015']
metrics_path: '/metrics'
scheme: 'http'