This repository was archived by the owner on Sep 2, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 8 files changed +96
-11
lines changed Expand file tree Collapse file tree 8 files changed +96
-11
lines changed Original file line number Diff line number Diff line change
1
+ APP_ENV = dev
2
+ DATABASE_URL = mongodb://mongo:27017
3
+ JWT_SECRET = changeMe
4
+ MAIL_PROVIDER = dev
5
+ STORAGE_PROVIDER = local
6
+
7
+ FROM_NAME = Your company
8
+ REDIS_HOST = redis:6379
9
+ REDIS_PASSWORD =
10
+ LOCAL_STORAGE_URL = http://localhost:8099
Original file line number Diff line number Diff line change
1
+ FROM golang:1.16
2
+
3
+ WORKDIR /app
4
+
5
+ COPY go.mod ./
6
+ COPY go.sum ./
7
+ COPY .env .env
8
+
9
+ RUN go mod download
10
+
11
+ COPY . .
12
+
13
+ RUN cd cmd && go build -o ../server
14
+
15
+ CMD [ "/app/server" ]
Original file line number Diff line number Diff line change 5
5
@cd cmd && rm -rf staticbackend && go build -o staticbackend
6
6
7
7
start : build
8
- @./cmd/staticbackend -host localhost
8
+ @./cmd/staticbackend
9
9
10
10
deploy :
11
11
CGO_ENABLED=0 go build
@@ -14,6 +14,9 @@ deploy:
14
14
test :
15
15
@JWT_SECRET=okdevmode go test --race --cover ./...
16
16
17
+ docker :
18
+ docker build . -t staticbackend:latest
19
+
17
20
pkg : build
18
21
@rm -rf dist/*
19
22
@echo " building linux binaries"
Original file line number Diff line number Diff line change @@ -110,6 +110,44 @@ This is one example of your typical day-to-day workflow using StaticBackend.
110
110
111
111
Please refer to this [ guide here] ( https://staticbackend.com/getting-started/self-hosting/ ) .
112
112
113
+ If you have Docker & Docker Compose ready, here's how you can have your server
114
+ up and running in dev mode in 30 seconds:
115
+
116
+ ``` shell
117
+ $
> git clone
[email protected] :staticbackendhq/core.git
118
+ $> cd core
119
+ $> docker build . -t staticbackend:latest
120
+ $> docker-compuse -f docker-compose-demo.yml up
121
+ ```
122
+
123
+ Test your instance:
124
+
125
+ ``` shell
126
+ $> curl -v http://localhost:8099/db/test
127
+ ```
128
+
129
+ You should get an error as follow:
130
+
131
+ ``` shell
132
+ < HTTP/1.1 401 Unauthorized
133
+ < Content-Type: text/plain; charset=utf-8
134
+ < Vary: Origin
135
+ < Vary: Access-Control-Request-Method
136
+ < Vary: Access-Control-Request-Headers
137
+ < X-Content-Type-Options: nosniff
138
+ < Date: Tue, 03 Aug 2021 11:40:15 GMT
139
+ < Content-Length: 33
140
+ <
141
+ invalid StaticBackend public key
142
+ ```
143
+
144
+ This is normal, as you're trying to request protected API, but you're all set.
145
+
146
+ The next step is to visit [ http://localhost:8099 ] ( http://localhost:8099 ) and
147
+ create your first app. Please note that in dev mode you'll have to look at your
148
+ docker compose output terminal to see the content of the email after creating
149
+ your app.
150
+
113
151
## Documentation
114
152
115
153
We're trying to have the best experience possible reading our documentation.
Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
- "flag "
4
+ "os "
5
5
backend "staticbackend"
6
6
)
7
7
8
8
func main () {
9
- dbHost := flag .String ("host" , "localhost" , "Hostname for mongodb" )
10
- port := flag .String ("port" , "8099" , "HTTP port to listen on" )
11
- flag .Parse ()
9
+ dbHost := os .Getenv ("DATABASE_URL" )
10
+ port := os .Getenv ("PORT" )
11
+ if len (port ) == 0 {
12
+ port = "8099"
13
+ }
12
14
13
- backend .Start (* dbHost , * port )
15
+ backend .Start (dbHost , port )
14
16
}
Original file line number Diff line number Diff line change
1
+ version : " 3"
2
+ services :
3
+ sb :
4
+ image : staticbackend:latest
5
+ ports :
6
+ - " 8099:8099"
7
+ env_file :
8
+ - ./.demo.env
9
+
10
+ mongo :
11
+ image : mongo:3-stretch
12
+ volumes :
13
+ - ./mongodata:/data/db/mongo
14
+ ports :
15
+ - " 27017:27017"
16
+
17
+ redis :
18
+ image : " redis:alpine"
19
+ ports :
20
+ - " 6379:6379"
Original file line number Diff line number Diff line change 36
36
)
37
37
38
38
func TestMain (m * testing.M ) {
39
- if err := openDatabase ("localhost" ); err != nil {
39
+ if err := openDatabase ("mongodb:// localhost:27017 " ); err != nil {
40
40
log .Fatal (err )
41
41
}
42
42
Original file line number Diff line number Diff line change @@ -174,10 +174,7 @@ func initServices(dbHost string) {
174
174
}
175
175
}
176
176
func openDatabase (dbHost string ) error {
177
- uri := os .Getenv ("DATABASE_URL" )
178
- if dbHost == "localhost" {
179
- uri = "mongodb://localhost:27017"
180
- }
177
+ uri := dbHost
181
178
182
179
ctx , _ := context .WithTimeout (context .Background (), 2 * time .Second )
183
180
cl , err := mongo .Connect (ctx , options .Client ().ApplyURI (uri ))
You can’t perform that action at this time.
0 commit comments