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
Binary file removed .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Dockerfile
docker-compose.yml
*.md
.DS_Store
hustle-backend
chimes-backend
4 changes: 2 additions & 2 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Docker Build & Push and Deploy to dev for hustle-backend
name: Docker Build & Push and Deploy to dev for chimes-backend

on:
push:
Expand Down Expand Up @@ -28,7 +28,7 @@ jobs:
file: ./Dockerfile
platforms: linux/amd64
push: true
tags: cornellappdev/hustle-dev:${{ steps.vars.outputs.sha_short }}
tags: cornellappdev/chimes-dev:${{ steps.vars.outputs.sha_short }}
- name: Remote SSH and Deploy
uses: appleboy/ssh-action@master
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Docker Build & Push and Deploy to prod for hustle-backend
name: Docker Build & Push and Deploy to prod for chimes-backend

on:
push:
Expand Down Expand Up @@ -27,7 +27,7 @@ jobs:
context: ./
file: ./Dockerfile
push: true
tags: cornellappdev/hustle-prod:${{ steps.vars.outputs.sha_short }}
tags: cornellappdev/chimes-prod:${{ steps.vars.outputs.sha_short }}
- name: Remote SSH and Deploy
uses: appleboy/ssh-action@master
env:
Expand Down
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*.dll
*.so
*.dylib
hustle-backend
chimes-backend

# Test binary, built with `go test -c`
*.test
Expand All @@ -31,4 +31,7 @@ service-account-key.json

# Editor/IDE
# .idea/
# .vscode/
.vscode/

.DS_Store

6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o /hustle-backend
RUN CGO_ENABLED=0 GOOS=linux go build -o /chimes-backend

FROM gcr.io/distroless/base-debian11
WORKDIR /
COPY --from=build-stage /hustle-backend /hustle-backend
COPY --from=build-stage /chimes-backend /chimes-backend
EXPOSE 8080
USER nonroot:nonroot
ENTRYPOINT ["/hustle-backend"]
ENTRYPOINT ["/chimes-backend"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# center-backend
# chimes-backend
7 changes: 4 additions & 3 deletions auth/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package auth

import (
"fmt"
"log"
"os"
"time"
"log"

"github.com/golang-jwt/jwt/v5"
)

Expand Down Expand Up @@ -67,7 +68,7 @@ func (j *JWTService) generateAccessToken(userID, email string) (string, error) {
ExpiresAt: jwt.NewNumericDate(time.Now().Add(15 * time.Minute)),
IssuedAt: jwt.NewNumericDate(time.Now()),
NotBefore: jwt.NewNumericDate(time.Now()),
Issuer: "hustle-backend",
Issuer: "chimes-backend",
Subject: userID,
},
}
Expand All @@ -82,7 +83,7 @@ func (j *JWTService) generateRefreshToken(userID string) (string, error) {
ExpiresAt: jwt.NewNumericDate(time.Now().Add(7 * 24 * time.Hour)), // 7 days
IssuedAt: jwt.NewNumericDate(time.Now()),
NotBefore: jwt.NewNumericDate(time.Now()),
Issuer: "hustle-backend",
Issuer: "chimes-backend",
Subject: userID,
}

Expand Down
8 changes: 4 additions & 4 deletions controllers/healthcheck.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package controllers

import (
"net/http"
"net/http"

"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
)

// GET /healthcheck
// Get healthcheck
func HealthCheck(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "Hustle is healthy!"})
}
c.JSON(http.StatusOK, gin.H{"status": "Chimes is healthy!"})
}
4 changes: 2 additions & 2 deletions controllers/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package controllers
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/cuappdev/hustle-backend/models"
"github.com/cuappdev/hustle-backend/services"
"github.com/cuappdev/chimes-backend/models"
"github.com/cuappdev/chimes-backend/services"
)

// Struct for register token
Expand Down
6 changes: 3 additions & 3 deletions controllers/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"strings"

"github.com/gin-gonic/gin"
"github.com/cuappdev/hustle-backend/models"
"github.com/cuappdev/hustle-backend/middleware"
"github.com/cuappdev/hustle-backend/auth"
"github.com/cuappdev/chimes-backend/models"
"github.com/cuappdev/chimes-backend/middleware"
"github.com/cuappdev/chimes-backend/auth"
firebaseauth "firebase.google.com/go/v4/auth"
)

Expand Down
39 changes: 27 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
version: "3.8"

services:
db:
image: postgres:16
environment:
POSTGRES_DB: chimes
POSTGRES_USER: postgres
POSTGRES_PASSWORD: tnt
volumes:
- pg_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres -d chimes"]
interval: 5s
timeout: 5s
retries: 10
restart: unless-stopped

app:
image: cornellappdev/hustle-dev:${IMAGE_TAG}
build: .
image: cornellappdev/chimes-dev:${IMAGE_TAG}
env_file: .env
environment:
DB_HOST: db
DB_PORT: 5432
depends_on:
db:
condition: service_healthy
volumes:
- ./service-account-key.json:/service-account-key.json
ports:
- target: 8080
published: 8080
protocol: tcp
mode: host
- "8080:8080"
restart: unless-stopped
deploy:
replicas: 1
placement:
constraints:
- node.role == manager

volumes:
pg_data:
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/cuappdev/hustle-backend
module github.com/cuappdev/chimes-backend

go 1.25.1

Expand Down
Binary file modified hustle-backend
Binary file not shown.
25 changes: 13 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"context"
"log"
"os"

"github.com/cuappdev/chimes-backend/auth"
"github.com/cuappdev/chimes-backend/controllers"
"github.com/cuappdev/chimes-backend/middleware"
"github.com/cuappdev/chimes-backend/models"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/cuappdev/hustle-backend/models"
"github.com/cuappdev/hustle-backend/controllers"
"github.com/cuappdev/hustle-backend/auth"
"github.com/cuappdev/hustle-backend/middleware"
)

func main() {
Expand All @@ -18,8 +19,9 @@ func main() {
log.Println("Error loading .env file.")
}

log.Println("Starting hustle-backend...")
r := gin.Default()
log.Println("Starting chimes-backend...")
r := gin.Default()
r.SetTrustedProxies(nil) // Trust no proxies for now, will configure later
log.Println("Connecting to database...")
// Connect to DB
if err := models.ConnectDatabase(); err != nil {
Expand All @@ -44,12 +46,11 @@ func main() {
if err := auth.InitFirebase(serviceAccountPath); err != nil {
log.Printf("[FATAL] Firebase Messaging init failed: %v", err)
}


log.Println("Setting up routes...")
// Public routes
r.GET("/healthcheck", controllers.HealthCheck)

// Auth routes (public)
api := r.Group("/api")
{
Expand All @@ -66,12 +67,12 @@ func main() {
authd.POST("/users", controllers.CreateUser)
// Notification routes
authd.POST("/fcm/register", controllers.RegisterFCMToken)
authd.DELETE("/fcm/delete", controllers.DeleteFCMToken)
authd.POST("/fcm/test", controllers.SendTestNotification)
authd.DELETE("/fcm/delete", controllers.DeleteFCMToken)
authd.POST("/fcm/test", controllers.SendTestNotification)
}
log.Println("Server starting on :8080")

r.Run()
r.Run()
}

func getwdSafe() string {
Expand All @@ -80,4 +81,4 @@ func getwdSafe() string {
return "unknown"
}
return wd
}
}
6 changes: 4 additions & 2 deletions middleware/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"strings"

firebaseauth "firebase.google.com/go/v4/auth"
"github.com/cuappdev/chimes-backend/auth"
"github.com/gin-gonic/gin"
"github.com/cuappdev/hustle-backend/auth"
)

type ctxKey string
Expand Down Expand Up @@ -76,6 +76,8 @@ func RequireFirebaseUser(ac *firebaseauth.Client) gin.HandlerFunc {
// Helper to read the uid in handlers:
func UIDFrom(c *gin.Context) string {
v := c.Request.Context().Value(UIDKey)
if s, ok := v.(string); ok { return s }
if s, ok := v.(string); ok {
return s
}
return ""
}
2 changes: 1 addition & 1 deletion models/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func ConnectDatabase() error {
// Build connection string from env variables
host := getEnv("DB_HOST", "localhost")
user := getEnv("DB_USER", "postgres")
dbname := getEnv("DB_NAME", "hustle")
dbname := getEnv("DB_NAME", "chimes")
port := getEnv("DB_PORT", "5432")
password := getEnv("DB_PASSWORD", "")
sslmode := getEnv("DB_SSLMODE", "require")
Expand Down
4 changes: 2 additions & 2 deletions services/notificationservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package services
import (
"context"
"firebase.google.com/go/v4/messaging"
"github.com/cuappdev/hustle-backend/auth"
"github.com/cuappdev/hustle-backend/models"
"github.com/cuappdev/chimes-backend/auth"
"github.com/cuappdev/chimes-backend/models"
)

type NotificationPayload struct {
Expand Down