fix: rename vars

This commit is contained in:
Lakhan Samani
2021-08-02 23:03:40 +05:30
parent 66ac3caf8c
commit 3b7ca9c02d
12 changed files with 60 additions and 32 deletions

20
.env Normal file
View File

@@ -0,0 +1,20 @@
DATABASE_URL=postgres://localhost:5432/lakhansamani
DATABASE_TYPE=postgres
COOKIE_NAME=authorizer
ENV=development
FORGOT_PASSWORD_URI=reset-password
FRONTEND_URL=http://localhost:1234
GITHUB_CLIENT_ID=Iv1.be6b1b73c67b5493
GITHUB_CLIENT_SECRET=458c5bdd6614eb1ec917a6a049dfbe625129431c
GOOGLE_CLIENT_ID=678083311263-1n0k7fmbaq4k24pd1jslboj24bjmjub7.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=oxmxasg70lHWp71xqzEte5wv
JWT_SECRET=randome123
JWT_TYPE=HS256
SENDER_EMAIL=abhay.m.samani@gmail.com
SENDER_PASSWORD="bhySmn@q1w2e3#"
AUTHORIZER_URL=http://localhost:8080
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
ADMIN_SECRET=admin
ENV=production
DISABLE_EMAIL_VERICATION=true

7
Makefile Normal file
View File

@@ -0,0 +1,7 @@
DEFAULT_VERSION=0.1.0-local
VERSION := $(or $(VERSION),$(DEFAULT_VERSION))
cmd:
cd server && go build -ldflags "-w -X main.Version=$(VERSION)" -o '../build/server'
clean:
rm -rf build

BIN
build/server Executable file

Binary file not shown.

View File

@@ -1,7 +0,0 @@
DEFAULT_VERSION=0.1.0-local
VERSION := $(or $(VERSION),$(DEFAULT_VERSION))
cmd:
go build -ldflags "-w -X main.Version=$(VERSION)"
clean:
rm -rf server

View File

@@ -14,7 +14,7 @@ var (
JWT_SECRET = ""
ALLOWED_ORIGINS = []string{}
ALLOWED_CALLBACK_URLS = []string{}
AUTHORIZER_DOMAIN = ""
AUTHORIZER_URL = ""
PORT = "8080"
REDIS_URL = ""
IS_PROD = false

View File

@@ -17,7 +17,7 @@ var Version string
func ParseArgs() {
dbURL := flag.String("database_url", "", "Database connection string")
dbType := flag.String("databse_type", "", "Database type, possible values are postgres,mysql,sqlit")
authroizerDomain := flag.String("authorizer_domain", "", "Domain name for authorizer instance, eg: https://xyz.herokuapp.com")
authorizerURL := flag.String("AUTHORIZER_URL", "", "URL for authorizer instance, eg: https://xyz.herokuapp.com")
flag.Parse()
if *dbURL != "" {
constants.DATABASE_URL = *dbURL
@@ -27,8 +27,8 @@ func ParseArgs() {
constants.DATABASE_TYPE = *dbType
}
if *authroizerDomain != "" {
constants.AUTHORIZER_DOMAIN = *authroizerDomain
if *authorizerURL != "" {
constants.AUTHORIZER_URL = *authorizerURL
}
}
@@ -51,7 +51,7 @@ func InitEnv() {
constants.SENDER_PASSWORD = os.Getenv("SENDER_PASSWORD")
constants.JWT_SECRET = os.Getenv("JWT_SECRET")
constants.JWT_TYPE = os.Getenv("JWT_TYPE")
constants.AUTHORIZER_DOMAIN = strings.TrimSuffix(os.Getenv("AUTHORIZER_DOMAIN"), "/")
constants.AUTHORIZER_URL = strings.TrimSuffix(os.Getenv("AUTHORIZER_URL"), "/")
constants.PORT = os.Getenv("PORT")
constants.REDIS_URL = os.Getenv("REDIS_URL")
constants.COOKIE_NAME = os.Getenv("COOKIE_NAME")
@@ -83,23 +83,31 @@ func InitEnv() {
constants.IS_PROD = false
}
allowedOrigins := strings.Split(os.Getenv("ALLOWED_ORIGINS"), ",")
for i, val := range allowedOrigins {
allowedOrigins[i] = strings.TrimSpace(val)
allowedOriginsSplit := strings.Split(os.Getenv("ALLOWED_ORIGINS"), ",")
allowedOrigins := []string{}
for _, val := range allowedOriginsSplit {
trimVal := strings.TrimSpace(val)
if trimVal != "" {
allowedOrigins = append(allowedOrigins, trimVal)
}
}
if len(allowedOrigins) == 0 {
allowedOrigins = []string{"*"}
}
constants.ALLOWED_ORIGINS = allowedOrigins
allowedCallback := strings.Split(os.Getenv("ALLOWED_CALLBACK_URLS"), ",")
for i, val := range allowedOrigins {
allowedCallback[i] = strings.TrimSpace(val)
allowedCallbackSplit := strings.Split(os.Getenv("ALLOWED_CALLBACK_URLS"), ",")
allowedCallbacks := []string{}
for _, val := range allowedCallbackSplit {
trimVal := strings.TrimSpace(val)
if trimVal != "" {
allowedCallbacks = append(allowedCallbacks, trimVal)
}
}
if len(allowedCallback) == 0 {
allowedCallback = []string{"*"}
if len(allowedCallbackSplit) == 0 {
allowedCallbackSplit = []string{"*"}
}
constants.ALLOWED_CALLBACK_URLS = allowedCallback
constants.ALLOWED_CALLBACK_URLS = allowedCallbackSplit
ParseArgs()
if constants.DATABASE_URL == "" {

View File

@@ -22,8 +22,8 @@ func AppHandler() gin.HandlerFunc {
}
c.HTML(http.StatusOK, "app.tmpl", gin.H{
"data": map[string]string{
"domain": c.Request.Host,
"redirect_url": "http://localhost:8080/app",
"authorizerURL": c.Request.Host,
"redirect_url": "http://localhost:8080/app",
},
})
}

View File

@@ -15,8 +15,8 @@ func GraphqlHandler() gin.HandlerFunc {
h := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}))
return func(c *gin.Context) {
if constants.AUTHORIZER_DOMAIN == "" {
constants.AUTHORIZER_DOMAIN = "https://" + c.Request.Host
if constants.AUTHORIZER_URL == "" {
constants.AUTHORIZER_URL = "https://" + c.Request.Host
}
h.ServeHTTP(c.Writer, c.Request)
}

View File

@@ -50,11 +50,11 @@ func main() {
r.GET("/", handlers.PlaygroundHandler())
r.POST("/graphql", handlers.GraphqlHandler())
r.GET("/verify_email", handlers.VerifyEmailHandler())
r.GET("/login/:oauth_provider", handlers.OAuthLoginHandler())
r.GET("/callback/:oauth_provider", handlers.OAuthCallbackHandler())
r.GET("/oauth_login/:oauth_provider", handlers.OAuthLoginHandler())
r.GET("/oauth_callback/:oauth_provider", handlers.OAuthCallbackHandler())
// login wall app related routes
r.Static("/app/build", "../app/build")
r.Static("/app/build", "app/build")
r.LoadHTMLGlob("templates/*")
r.GET("/app", handlers.AppHandler())

View File

@@ -20,7 +20,7 @@ func InitOAuth() {
OAuthProvider.GoogleConfig = &oauth2.Config{
ClientID: constants.GOOGLE_CLIENT_ID,
ClientSecret: constants.GOOGLE_CLIENT_SECRET,
RedirectURL: constants.AUTHORIZER_DOMAIN + "/callback/google",
RedirectURL: constants.AUTHORIZER_URL + "/oauth_callback/google",
Endpoint: googleOAuth2.Endpoint,
Scopes: []string{"https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile"},
}
@@ -29,7 +29,7 @@ func InitOAuth() {
OAuthProvider.GithubConfig = &oauth2.Config{
ClientID: constants.GITHUB_CLIENT_ID,
ClientSecret: constants.GITHUB_CLIENT_SECRET,
RedirectURL: constants.AUTHORIZER_DOMAIN + "/callback/github",
RedirectURL: constants.AUTHORIZER_URL + "/oauth_callback/github",
Endpoint: githubOAuth2.Endpoint,
}
}
@@ -37,7 +37,7 @@ func InitOAuth() {
// OAuthProvider.FacebookConfig = &oauth2.Config{
// ClientID: constants.FACEBOOK_CLIENT_ID,
// ClientSecret: constants.FACEBOOK_CLIENT_SECRET,
// RedirectURL: "/callback/facebook/",
// RedirectURL: "/oauth_callback/facebook/",
// Endpoint: facebookOAuth2.Endpoint,
// }
// }

View File

@@ -26,7 +26,7 @@ func SendVerificationMail(toEmail, token string) error {
<a href="%s">Click here to verify</a>
</body>
</html>
`, constants.AUTHORIZER_DOMAIN+"/verify_email"+"?token="+token)
`, constants.AUTHORIZER_URL+"/verify_email"+"?token="+token)
bodyMessage := sender.WriteHTMLEmail(Receiver, Subject, message)
return sender.SendMail(Receiver, Subject, bodyMessage)