diff --git a/backend/config/app.go b/backend/config/app.go index 7b6f45ac..b3e611ca 100644 --- a/backend/config/app.go +++ b/backend/config/app.go @@ -3,9 +3,10 @@ package config import "fmt" type ApplicationSettings struct { - Port uint16 `env:"PORT"` - Host string `env:"HOST"` - BaseUrl string `env:"BASE_URL"` + Port uint16 `env:"PORT"` + Host string `env:"HOST"` + BaseUrl string `env:"BASE_URL"` + PublicUrl string `env:"PUBLIC_URL"` } func (s *ApplicationSettings) ApplicationURL() string { diff --git a/backend/main.go b/backend/main.go index 2b7a97a0..84239695 100644 --- a/backend/main.go +++ b/backend/main.go @@ -21,6 +21,7 @@ import ( "github.com/GenerateNU/sac/backend/integrations/email" "github.com/GenerateNU/sac/backend/integrations/file" "github.com/GenerateNU/sac/backend/integrations/oauth/soth/sothic" + "github.com/GenerateNU/sac/backend/search" "github.com/GenerateNU/sac/backend/server" "github.com/GenerateNU/sac/backend/telemetry" "github.com/GenerateNU/sac/backend/utilities" @@ -97,14 +98,13 @@ func checkServerRunning(host string, port uint16) error { } func seedSearchData(db *gorm.DB) { - slog.Info("to appease linter", "seedSearch", true, "db", db) - // if err := search.SeedClubs(db); err != nil { - // return - // } - - // if err := search.SeedEvents(db); err != nil { - // return - // } + if err := search.SeedClubs(db); err != nil { + return + } + + if err := search.SeedEvents(db); err != nil { + return + } } func startBackgroundJobs(ctx context.Context, db *gorm.DB) { diff --git a/backend/redis_entrypoint.sh b/backend/redis_entrypoint.sh index ffa4913b..37ba71ef 100644 --- a/backend/redis_entrypoint.sh +++ b/backend/redis_entrypoint.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # set up redis configuration directory mkdir -p /usr/local/etc/redis @@ -12,7 +12,7 @@ if [ -n ${REDIS_USERNAME} ] && [ -n ${REDIS_PASSWORD} ]; then fi # disable default user -if [ $(echo ${REDIS_DISABLE_DEFAULT_USER}) == "true" ]; then +if [ "$REDIS_DISABLE_DEFAULT_USER" == "true" ]; then echo "user default off nopass nocommands" >> /usr/local/etc/redis/custom_aclfile.acl fi diff --git a/backend/search/base/controller.go b/backend/search/base/controller.go index bd8a6b47..02909ace 100644 --- a/backend/search/base/controller.go +++ b/backend/search/base/controller.go @@ -1,7 +1,9 @@ package base import ( + "log" "net/http" + "os" search_types "github.com/GenerateNU/sac/backend/search/types" "github.com/GenerateNU/sac/backend/utilities" @@ -30,14 +32,18 @@ func NewSearchController(searchService SearchServiceInterface) *SearchController // @Failure 500 {object} error // @Router /search/clubs [get] func (s *SearchController) SearchClubs(c *fiber.Ctx) error { + log.SetOutput(os.Stdout) + var searchQuery search_types.ClubSearchRequest + log.Println("RAHHHHHH") if err := c.BodyParser(&searchQuery); err != nil { return utilities.InvalidJSON() } result, err := s.searchService.SearchClubs(searchQuery) if err != nil { + log.Println("RAHHHHHH XD") return err } diff --git a/backend/search/base/transactions.go b/backend/search/base/transactions.go index 8ddfdce3..c07a9e2d 100644 --- a/backend/search/base/transactions.go +++ b/backend/search/base/transactions.go @@ -3,6 +3,7 @@ package base import ( "fmt" "io" + "log" "log/slog" "net/http" @@ -18,16 +19,21 @@ import ( func doSearchGetRequest[T, V any](url string, requestBody T) (*V, error) { payload, err := json.Marshal(requestBody) if err != nil { + log.Println("json marshal failed") return nil, err } resp, err := utilities.Request(http.MethodGet, fmt.Sprintf("%s%s", constants.SEARCH_URI, url), payload, utilities.JSON()) if err != nil { + log.Println("response failed") return nil, err } defer resp.Body.Close() responseBody, err := io.ReadAll(resp.Body) + log.Println("response body VVV") + log.Println(string(responseBody)) + if err != nil { return nil, err } @@ -44,7 +50,8 @@ func doSearchGetRequest[T, V any](url string, requestBody T) (*V, error) { func Search[T types.Searchable](db *gorm.DB, query types.SearchRequest) (*types.SearchResult[T], error) { result, err := doSearchGetRequest[types.SearchEndpointRequest, types.SearchEndpointResponse](fmt.Sprintf("/%s/_search", query.Index()), query.ToSearchEndpointRequest()) if err != nil { - return nil, nil + log.Println("dosearchgetrequest failed") + return nil, err } ids := make([]string, len(result.Hits.Hits)) @@ -55,7 +62,8 @@ func Search[T types.Searchable](db *gorm.DB, query types.SearchRequest) (*types. var results []T if err = query.Preload(db).Where("id IN ?", ids).Find(&results).Error; err != nil { - return nil, nil + log.Println("query preload failed") + return nil, err } return &types.SearchResult[T]{ diff --git a/backend/server/server.go b/backend/server/server.go index a916d37c..8c10b6d3 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -57,8 +57,10 @@ func Init(db *gorm.DB, stores *store.Stores, integrations integrations.Integrati applicationURL := settings.Application.ApplicationURL() - msftProvider := msft.New(settings.Microsft.Key, settings.Microsft.Secret, fmt.Sprintf("%s/api/v1/auth/microsoftonline/callback", applicationURL), settings.Microsft.Tenant) - googProvider := goog.New(settings.Google.Key, settings.Google.Secret, fmt.Sprintf("%s/api/v1/auth/google/callback", applicationURL)) + publicURL := settings.Application.PublicUrl + + msftProvider := msft.New(settings.Microsft.Key, settings.Microsft.Secret, fmt.Sprintf("%s/api/v1/auth/microsoftonline/callback", publicURL), settings.Microsft.Tenant) + googProvider := goog.New(settings.Google.Key, settings.Google.Secret, fmt.Sprintf("%s/api/v1/auth/google/callback", publicURL)) authMiddleware := authMiddleware.New( db, diff --git a/config/.env.template b/config/.env.template index 79c692d7..bfce26fc 100644 --- a/config/.env.template +++ b/config/.env.template @@ -1,6 +1,7 @@ SAC_APPLICATION_PORT="8080" SAC_APPLICATION_HOST="127.0.0.1" SAC_APPLICATION_BASE_URL="http://127.0.0.1" +SAC_APPLICATION_PUBLIC_URL="http://127.0.0.1" SAC_DB_USERNAME="postgres" SAC_DB_PASSWORD="password" diff --git a/deployment/Caddyfile b/deployment/Caddyfile index 38e2e44c..062cdc7f 100644 --- a/deployment/Caddyfile +++ b/deployment/Caddyfile @@ -1,3 +1,3 @@ -sac.tech0tron.net { +studentactivitycalendar.xyz { reverse_proxy sac_webserver:8080 } \ No newline at end of file diff --git a/deployment/compose.yml b/deployment/compose.yml index 4d47f47c..ab9e9847 100644 --- a/deployment/compose.yml +++ b/deployment/compose.yml @@ -30,7 +30,7 @@ services: dockerfile: ../backend/Dockerfile.redis container_name: redis_session ports: - - 6380:6379 + - "6379" environment: - REDIS_USERNAME=${SAC_REDIS_SESSION_USERNAME} - REDIS_PASSWORD=${SAC_REDIS_SESSION_PASSWORD} @@ -42,8 +42,8 @@ services: context: ../backend dockerfile: ../backend/Dockerfile.redis container_name: redis_limiter - ports: - - 6381:6379 + expose: + - "6379" environment: - REDIS_USERNAME=${SAC_REDIS_LIMITER_USERNAME} - REDIS_PASSWORD=${SAC_REDIS_LIMITER_PASSWORD} @@ -74,8 +74,9 @@ services: ports: - 9200:9200 - 9600:9600 # required for Performance Analyzer - networks: - - opensearch-net + expose: + - "9200" + - "9600" opensearch-dashboards: image: opensearchproject/opensearch-dashboards:latest container_name: opensearch-dashboards @@ -86,8 +87,6 @@ services: environment: OPENSEARCH_HOSTS: '["http://opensearch-node1:9200"]' DISABLE_SECURITY_DASHBOARDS_PLUGIN: true - networks: - - opensearch-net volumes: redis-session-data: @@ -96,6 +95,3 @@ volumes: caddy_data: external: true caddy_config: - -networks: - opensearch-net: