forked from xcat2/goconserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple web interface for goconserver
Web interface is implemented with frontend techniques like webpack, gulp, jquery, xtermjs and scss. At golang part, goconserver also act as a web server to accept the request from browser.
- Loading branch information
Showing
22 changed files
with
689 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,5 @@ vendor/ | |
goconserver | ||
congo | ||
build | ||
frontend/package-lock.json | ||
frontend/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package api | ||
|
||
import ( | ||
"compress/gzip" | ||
"fmt" | ||
"github.com/gorilla/mux" | ||
"github.com/xcat2/goconserver/console" | ||
"golang.org/x/net/websocket" | ||
"io" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
type gzipResponseWriter struct { | ||
io.Writer | ||
http.ResponseWriter | ||
} | ||
|
||
func (w gzipResponseWriter) Write(b []byte) (int, error) { | ||
return w.Writer.Write(b) | ||
} | ||
|
||
func MakeGzipHandler(handler http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
// Check if the client can accept the gzip encoding. | ||
if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { | ||
handler.ServeHTTP(w, r) | ||
return | ||
} | ||
|
||
// Set the HTTP header indicating encoding. | ||
w.Header().Set("Content-Encoding", "gzip") | ||
gz := gzip.NewWriter(w) | ||
defer gz.Close() | ||
gzw := gzipResponseWriter{Writer: gz, ResponseWriter: w} | ||
handler.ServeHTTP(gzw, r) | ||
}) | ||
} | ||
|
||
func WebHandler() http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
plog.Info(fmt.Sprintf("Receive %s request %s from %s.", r.Method, r.URL.Path, r.RemoteAddr)) | ||
if r.URL.EscapedPath() == "/" || r.URL.EscapedPath() == "/index.html" { | ||
w.Header().Add("Cache-Control", "no-store") | ||
} | ||
http.FileServer(http.Dir(serverConfig.API.DistDir)).ServeHTTP(w, r) | ||
}) | ||
} | ||
|
||
func RegisterBackendHandler(router *mux.Router) { | ||
router.PathPrefix("/session").Handler(websocket.Handler(websocketHandler)) | ||
router.PathPrefix("/").Handler(MakeGzipHandler(WebHandler())) | ||
} | ||
|
||
func websocketHandler(ws *websocket.Conn) { | ||
plog.Info(fmt.Sprintf("Recieve websocket request from %s\n", ws.RemoteAddr().String())) | ||
console.AcceptWesocketClient(ws) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Setup node and npm environment | ||
Example for amd64 system | ||
|
||
``` | ||
wget https://nodejs.org/dist/v9.11.1/node-v9.11.1-linux-x64.tar.xz | ||
xz -d node-v9.11.1-linux-x64.tar.xz | ||
tar xvf node-v9.11.1-linux-x64.tar | ||
export PATH=$PATH:<work dir>/node-v9.11.1-linux-x64/bin | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var gp = require("gulp"); | ||
var webpack = require('webpack-stream'); | ||
|
||
gp.task("webpack", function() { | ||
return gp.src([ | ||
'src/js/index.js', | ||
'src/sass/index.scss' | ||
]) | ||
.pipe(webpack(require('./webpack.config.js'))) | ||
.pipe(gp.dest('../build/dist/')) | ||
}) | ||
|
||
gp.task("build", ["webpack"], function() { | ||
gp.src(['./src/html/*.html']) | ||
.pipe(gp.dest('../build/dist')) | ||
}) | ||
|
||
gp.task("run", ["build"], function() { | ||
gp.watch('src/*.js', function() { | ||
gulp.run('run'); | ||
}); | ||
}) |
Oops, something went wrong.