Skip to content

Commit

Permalink
Merge pull request #3 from keep-starknet-strange/feat/backend-init
Browse files Browse the repository at this point in the history
Feat: Initialize backend
  • Loading branch information
b-j-roberts authored Dec 17, 2024
2 parents 1542a05 + b5783bc commit f53557f
Show file tree
Hide file tree
Showing 45 changed files with 1,498 additions and 1,010 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Frontend ignored dirs
./apps/web/dist/
./apps/web/node_modules/
71 changes: 16 additions & 55 deletions apps/backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,61 +1,22 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Test binary, built with `go test -c`
*.test

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Coverage directory used by tools like istanbul
coverage
# Dependency directories (remove the comment below to include it)
# vendor/

# nyc test coverage
.nyc_output
# Go workspace files
go.work
go.work.sum

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
# env file
.env

# next.js build output
.next
20 changes: 20 additions & 0 deletions apps/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM golang:1.23.1-alpine

RUN apk add --no-cache bash curl git jq yq

# Copy over the configs
WORKDIR /configs
COPY ./apps/backend/configs/docker.config.yaml /configs/config.yaml

# Copy over the app
WORKDIR /app
COPY ./apps/backend/go.mod ./apps/backend/go.sum ./
RUN go mod download
COPY ./apps/backend .

# Build the app & run it
RUN go build -o broly-api ./cmd/broly-api/main.go

EXPOSE 8080

CMD ["./broly-api"]
20 changes: 20 additions & 0 deletions apps/backend/Dockerfile.consumer
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM golang:1.23.1-alpine

RUN apk add --no-cache bash curl git jq yq

# Copy over the configs
WORKDIR /configs
COPY ./apps/backend/configs/docker.config.yaml /configs/config.yaml

# Copy over the app
WORKDIR /app
COPY ./apps/backend/go.mod ./apps/backend/go.sum ./
RUN go mod download
COPY ./apps/backend .

# Build the app & run it
RUN go build -o consumer ./cmd/consumer/main.go

EXPOSE 8081

CMD ["./consumer"]
20 changes: 0 additions & 20 deletions apps/backend/app.js

This file was deleted.

90 changes: 0 additions & 90 deletions apps/backend/bin/www

This file was deleted.

22 changes: 22 additions & 0 deletions apps/backend/cmd/broly-api/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"fmt"
"net/http"

"github.com/keep-starknet-strange/broly/backend/internal/config"
"github.com/keep-starknet-strange/broly/backend/internal/db"
"github.com/keep-starknet-strange/broly/backend/routes"
)

func main() {
config.InitConfig()

db.InitDB()
defer db.CloseDB()

routes.InitRoutes()
fmt.Println("Listening on port:", config.Conf.Api.Port)
http.ListenAndServe(fmt.Sprintf(":%d", config.Conf.Api.Port), nil)
fmt.Println("Server stopped")
}
24 changes: 24 additions & 0 deletions apps/backend/cmd/consumer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"fmt"
"net/http"

"github.com/keep-starknet-strange/broly/backend/indexer"
"github.com/keep-starknet-strange/broly/backend/internal/config"
"github.com/keep-starknet-strange/broly/backend/internal/db"
)

func main() {
config.InitConfig()

db.InitDB()
defer db.CloseDB()

indexer.InitIndexerRoutes()
indexer.StartMessageProcessor()

fmt.Println("Listening on port:", config.Conf.Consumer.Port)
http.ListenAndServe(fmt.Sprintf(":%d", config.Conf.Consumer.Port), nil)
fmt.Println("Server stopped")
}
21 changes: 21 additions & 0 deletions apps/backend/configs/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Api:
Port: 8080
AllowOrigins:
- '*'
AllowMethods:
- GET
- POST
- PUT
- DELETE
- OPTIONS
AllowHeaders:
- Content-Type
Production: false
Admin: true
Consumer:
Port: 8081
Postgres:
Host: localhost
Port: 5432
User: broly-user
Name: broly-db
21 changes: 21 additions & 0 deletions apps/backend/configs/docker.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Api:
Port: 8080
AllowOrigins:
- '*'
AllowMethods:
- GET
- POST
- PUT
- DELETE
- OPTIONS
AllowHeaders:
- Content-Type
Production: false
Admin: true
Consumer:
Port: 8081
Postgres:
Host: broly-postgres-1
Port: 5432
User: broly-user
Name: broly-db
21 changes: 21 additions & 0 deletions apps/backend/configs/local.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Api:
Port: 8080
AllowOrigins:
- '*'
AllowMethods:
- GET
- POST
- PUT
- DELETE
- OPTIONS
AllowHeaders:
- Content-Type
Production: false
Admin: true
Consumer:
Port: 8081
Postgres:
Host: localhost
Port: 5432
User: broly-user
Name: broly-db
19 changes: 19 additions & 0 deletions apps/backend/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module github.com/keep-starknet-strange/broly/backend

go 1.23.1

require (
github.com/georgysavva/scany/v2 v2.1.3
github.com/jackc/pgx/v5 v5.7.1
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/kr/text v0.2.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/text v0.18.0 // indirect
)
Loading

0 comments on commit f53557f

Please sign in to comment.