Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
cicer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
meskio
cicer
Commits
e78b4ce2
Commit
e78b4ce2
authored
4 years ago
by
meskio
Browse files
Options
Downloads
Patches
Plain Diff
Serve properly a single page app
parent
fad4ff8c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.go
+28
-1
28 additions, 1 deletion
main.go
with
28 additions
and
1 deletion
main.go
+
28
−
1
View file @
e78b4ce2
...
@@ -4,12 +4,38 @@ import (
...
@@ -4,12 +4,38 @@ import (
"flag"
"flag"
"log"
"log"
"net/http"
"net/http"
"os"
"path/filepath"
"0xacab.org/meskio/cicer/api"
"0xacab.org/meskio/cicer/api"
"github.com/gorilla/mux"
"github.com/gorilla/mux"
"github.com/olivere/env"
"github.com/olivere/env"
)
)
type
handler
struct
{
assets
string
}
func
(
h
handler
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
path
,
err
:=
filepath
.
Abs
(
r
.
URL
.
Path
)
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusBadRequest
)
return
}
path
=
filepath
.
Join
(
h
.
assets
,
path
)
_
,
err
=
os
.
Stat
(
path
)
if
os
.
IsNotExist
(
err
)
{
http
.
ServeFile
(
w
,
r
,
h
.
assets
)
return
}
else
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
http
.
FileServer
(
http
.
Dir
(
h
.
assets
))
.
ServeHTTP
(
w
,
r
)
}
func
main
()
{
func
main
()
{
var
(
var
(
dbPath
=
flag
.
String
(
"db-path"
,
env
.
String
(
"./test.db"
,
"DB_PATH"
),
"Path where the sqlite will be located {DB_PATH}"
)
dbPath
=
flag
.
String
(
"db-path"
,
env
.
String
(
"./test.db"
,
"DB_PATH"
),
"Path where the sqlite will be located {DB_PATH}"
)
...
@@ -28,6 +54,7 @@ func main() {
...
@@ -28,6 +54,7 @@ func main() {
}
}
log
.
Println
(
"assets:"
,
*
assets
)
log
.
Println
(
"assets:"
,
*
assets
)
r
.
PathPrefix
(
"/"
)
.
Handler
(
http
.
FileServer
(
http
.
Dir
(
*
assets
)))
h
:=
handler
{
*
assets
}
r
.
PathPrefix
(
"/"
)
.
Handler
(
h
)
log
.
Fatal
(
http
.
ListenAndServe
(
*
addr
,
r
))
log
.
Fatal
(
http
.
ListenAndServe
(
*
addr
,
r
))
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment