This commit is contained in:
parent
c320cc8133
commit
fc4b4cc2e6
@ -15,6 +15,7 @@ import (
|
|||||||
// InitServer instanciate the main echo instance
|
// InitServer instanciate the main echo instance
|
||||||
func (ws *WS) InitServer(templatefiles *embed.FS, staticfiles *embed.FS) (err error) {
|
func (ws *WS) InitServer(templatefiles *embed.FS, staticfiles *embed.FS) (err error) {
|
||||||
ws.e = echo.New()
|
ws.e = echo.New()
|
||||||
|
ws.e.Pre(middleware.RemoveTrailingSlash())
|
||||||
ws.e.HideBanner = true
|
ws.e.HideBanner = true
|
||||||
ws.e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
|
ws.e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
|
||||||
Level: 5,
|
Level: 5,
|
||||||
@ -34,9 +35,23 @@ func (ws *WS) InitServer(templatefiles *embed.FS, staticfiles *embed.FS) (err er
|
|||||||
func (ws *WS) RunServer(config config.Config, templatefiles *embed.FS, staticfiles *embed.FS) (err error) {
|
func (ws *WS) RunServer(config config.Config, templatefiles *embed.FS, staticfiles *embed.FS) (err error) {
|
||||||
ws.InitServer(templatefiles, staticfiles)
|
ws.InitServer(templatefiles, staticfiles)
|
||||||
|
|
||||||
ws.e.GET("/", ws.Page.Process)
|
ws.e.GET("/", func(c echo.Context) (err error) {
|
||||||
ws.e.GET("/:ip", ws.Page.Process)
|
ws.Page.Process(c, "")
|
||||||
ws.e.GET("/static/*", func(c echo.Context) error {
|
return
|
||||||
|
})
|
||||||
|
ws.e.GET("/:ip", func(c echo.Context) (err error) {
|
||||||
|
ws.Page.Process(c, "")
|
||||||
|
return
|
||||||
|
})
|
||||||
|
ws.e.GET("/json", func(c echo.Context) (err error) {
|
||||||
|
ws.Page.Process(c, "json")
|
||||||
|
return
|
||||||
|
})
|
||||||
|
ws.e.GET("/json/:ip", func(c echo.Context) (err error) {
|
||||||
|
ws.Page.Process(c, "json")
|
||||||
|
return
|
||||||
|
})
|
||||||
|
ws.e.GET("/static/*", func(c echo.Context) (err error) {
|
||||||
return static.GetStatic(staticfiles, c)
|
return static.GetStatic(staticfiles, c)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package ws
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"git.paulbsd.com/paulbsd/dip/src/dip"
|
"git.paulbsd.com/paulbsd/dip/src/dip"
|
||||||
"git.paulbsd.com/paulbsd/dip/src/templates"
|
"git.paulbsd.com/paulbsd/dip/src/templates"
|
||||||
@ -18,9 +17,9 @@ func (p *Page) GetContent(c echo.Context) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process returns main webpage or a JSON
|
// Process returns main webpage or a JSON
|
||||||
func (p *Page) Process(c echo.Context) (err error) {
|
func (p *Page) Process(c echo.Context, querytype string) (err error) {
|
||||||
p.GetContent(c)
|
p.GetContent(c)
|
||||||
if strings.Contains(c.Request().Header.Get(echo.HeaderAccept), echo.MIMETextHTML) {
|
if querytype != "json" {
|
||||||
return c.Render(http.StatusOK, "index.html", p)
|
return c.Render(http.StatusOK, "index.html", p)
|
||||||
}
|
}
|
||||||
return c.JSONPretty(http.StatusOK, p.IP, " ")
|
return c.JSONPretty(http.StatusOK, p.IP, " ")
|
||||||
|
@ -13,10 +13,11 @@ var vue = new Vue({
|
|||||||
|
|
||||||
mounted () {
|
mounted () {
|
||||||
var ip = "";
|
var ip = "";
|
||||||
if (window.location.pathname.length > 1) {
|
if (window.location.pathname.length > 4) {
|
||||||
ip = window.location.pathname.split("/")[1];
|
ip = window.location.pathname.split("/")[1];
|
||||||
|
console.log(ip);
|
||||||
}
|
}
|
||||||
axios.get(`https://ip.paulbsd.com/${ip}`)
|
axios.get(`/json/${ip}`)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
this.dip = response.data
|
this.dip = response.data
|
||||||
})
|
})
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<html>
|
<html>
|
||||||
{{ template "head.html" .}}
|
{{ template "head.html" .}}
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="dip_main_div">
|
<div id="dip_main_div">
|
||||||
<h1 class="dip_h1">{{ .Title }}</h1>
|
<h1 class="dip_h1">{{ .Title }}</h1>
|
||||||
@ -21,7 +22,18 @@
|
|||||||
<td>Country</td>
|
<td>Country</td>
|
||||||
<td>{{ "{{" }} dip.country {{ "}}" }}</td>
|
<td>{{ "{{" }} dip.country {{ "}}" }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>ASN id</td>
|
||||||
|
<td>{{ "{{" }} dip.asn.id {{ "}}" }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>ASN name</td>
|
||||||
|
<td>
|
||||||
|
{{ "{{" }} dip.asn.name {{ "}}" }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</div>
|
</div>
|
||||||
{{ template "footer_js.html" .}}
|
{{ template "footer_js.html" .}}
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user