1
0
mirror of https://github.com/beego/bee.git synced 2024-11-21 18:40:54 +00:00

Generate WebSocket client in static/js

This commit is contained in:
Faissal Elamraoui 2017-01-27 16:57:37 +01:00
parent c5f8b8d28e
commit 62260c1033
3 changed files with 9 additions and 1 deletions

View File

@ -13,3 +13,4 @@ cmd_args: []
envs: []
database:
driver: "mysql"
enable_reload: false

View File

@ -16,5 +16,6 @@
"envs": [],
"database": {
"driver": "mysql"
}
},
"enable_reload": false
}

6
new.go
View File

@ -87,6 +87,7 @@ func createApp(cmd *Command, args []string) int {
os.Mkdir(path.Join(apppath, "static"), 0755)
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "static")+string(path.Separator), "\x1b[0m")
os.Mkdir(path.Join(apppath, "static", "js"), 0755)
WriteToFile(path.Join(apppath, "static", "js", "reload.min.js"), reloadJsClient)
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "static", "js")+string(path.Separator), "\x1b[0m")
os.Mkdir(path.Join(apppath, "static", "css"), 0755)
fmt.Fprintf(output, "\t%s%screate%s\t %s%s\n", "\x1b[32m", "\x1b[1m", "\x1b[21m", path.Join(apppath, "static", "css")+string(path.Separator), "\x1b[0m")
@ -294,6 +295,11 @@ var indextpl = `<!DOCTYPE html>
</div>
</footer>
<div class="backdrop"></div>
<script src="/static/js/reload.min.js"></script>
</body>
</html>
`
var reloadJsClient = `function b(a){var c=new WebSocket(a);c.onclose=function(){setTimeout(function(){b(a)},2E3)};c.onmessage=function(){location.reload()}}try{if(window.WebSocket)try{b("ws://localhost:12450/reload")}catch(a){console.error(a)}else console.log("Your browser does not support WebSockets.")}catch(a){console.error("Exception during connecting to Reload:",a)};
`