Add plugin widget
Change-Id: I55f006bfe1d60e6fe8e73b801171e507a62b97d9
diff --git a/service.go b/service.go
index ba009b8..5d82e15 100644
--- a/service.go
+++ b/service.go
@@ -68,7 +68,17 @@
func setupRouter() *gin.Engine {
r := gin.Default()
+ r.LoadHTMLGlob("templates/*")
+
+ r.GET("/index", func(c *gin.Context) {
+ c.HTML(http.StatusOK, "main.html", gin.H{
+ "title": "External Sale Plugin",
+ "korapServer": "https://korap.ids-mannheim.de/",
+ })
+ })
+
r.GET("/:corpus_id/:doc_id/:text_id", CheckSaleUrl)
+ r.Static("/assets", "./assets")
return r
}
diff --git a/service_test.go b/service_test.go
index a18c52e..5527c31 100644
--- a/service_test.go
+++ b/service_test.go
@@ -8,7 +8,7 @@
"github.com/stretchr/testify/assert"
)
-func TestPingRoute(t *testing.T) {
+func TestMappingRoute(t *testing.T) {
dir := t.TempDir()
@@ -33,3 +33,17 @@
assert.Equal(t, http.StatusOK, w.Code)
assert.Equal(t, "http://example.org", w.Body.String())
}
+
+func TestAssetRoute(t *testing.T) {
+
+ router := setupRouter()
+
+ w := httptest.NewRecorder()
+ req, _ := http.NewRequest(http.MethodGet, "/index", nil)
+
+ router.ServeHTTP(w, req)
+
+ assert.Equal(t, http.StatusOK, w.Code)
+ assert.Contains(t, w.Body.String(), "data-server=\"https://korap.ids-mannheim.de/\"")
+ assert.Contains(t, w.Body.String(), "<title>External Sale Plugin</title>")
+}
diff --git a/templates/main.html b/templates/main.html
new file mode 100644
index 0000000..3b41330
--- /dev/null
+++ b/templates/main.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <script data-server="{{ .korapServer }}" src="client.js"></script>
+ <title>{{ .title }}</title>
+ </head>
+ <body>
+ </body>
+</html>