Skip to content

Commit

Permalink
server the frontend and backend in a same place to enable https
Browse files Browse the repository at this point in the history
  • Loading branch information
Qiang Chen authored and Qiang Chen committed Feb 24, 2024
1 parent cab7b48 commit 1e1188f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 13 deletions.
14 changes: 4 additions & 10 deletions gomoku/script/tornado_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,15 @@ def get(self):
self.write(str.encode(response))


def make_app(debug):
handlers = [(r"/", MainHandler) ]
if debug:
handlers.append((r'/(.*)', web.StaticFileHandler, {'path': "./"}))
def make_app():
handlers = [(r"/next_step", MainHandler), (r"/", MainHandler) ]
handlers.append((r'/(.*)', web.StaticFileHandler, {'path': "./web/"}))
return tornado.web.Application(handlers)


if __name__ == "__main__":
debug = False
port = int(sys.argv[1])
if len(sys.argv) > 2:
print("DEBUG MODE, Server Web UI Here")
debug = True

app = make_app(debug)
app = make_app()
app.listen(port)
tornado.ioloop.IOLoop.current().start()

62 changes: 59 additions & 3 deletions gomoku/script/web/gomoku.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
<!DOCTYPE html>
<html lang="en">

<head>
<script>
// force to use unsecure http because the web has to access unsecure http API
document.addEventListener('DOMContentLoaded', function() {
if (location.protocol == 'https:') {
let httpUrl = `http:${location.href.substring(location.protocol.length)}`;
console.log(httpUrl);
document.body.innerHTML = `The website does not support https, please visit ${httpUrl}`;
// no link here because chrome will force it as https://
}
});
</script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-9D2R56XSHB"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-9D2R56XSHB');
</script>
<meta charset="UTF-8">
<title>Gomoku</title>
<title>ByteDance AI Gomoku</title>
<script src="js/jquery.js"></script>
</head>

<body>
<div>
<img id="hint" src="pic/line.png" hidden="hidden">
<div id="cubes">
</div>
Expand All @@ -16,11 +36,43 @@
<button onclick="rollback();" type="button">悔棋 (BACK)</button>
<button onclick="start();" type="button">重新开始 (RESTART)</button>
</div>
<hr/>

<div>
<a href="?person2person=true">玩家对战 (Play with Player)</a>
<br/>
<a href="?">人机对战 (Play with AI)</a>
</div>

<div>
<h2>ByteDance AI Gomoku - The Ultimate Five-in-a-Row AI</h2>
<span>
Welcome to ByteDance AI Gomoku (http://www.bytedance.ai/gomoku.html), Play against our advanced AI, which has been trained using the latest machine learning techniques to provide an immersive and challenging experience for players of all skill levels. <br/><br/>

Join us and test your strategic prowess in this ancient board game, also known as Five-in-a-Row, where the objective is to form an unbroken line of five stones of your color, horizontally, vertically, or diagonally. <br/><br/>

Are you ready for the ByteDance AI Gomoku challenge?
</span>
<br/>
<br/>
</div>
<hr/>
<div>
This project is built by <b><a target="_blank" href="http://qiangchen.org">qiangchen.org</a></b> and open sourced in <a target="_blank" href="https://github.com/fucusy/gomoku-first-move-always-win">Github fucusy/gomoku-first-move-always-win</a>
</div>
<hr/>
Notes
<div>
<br/>
<b><li id="collected-money">The AI could be out of service, contact [email protected] if you want to support it.</li></b>
<br/>
</div>
<div>
<li>2023-10-01: The AI is back using personal laptop as the server plus free port forwarding service from https://portmap.io/. The service could be shutdown anytime, contact [email protected] if you want to support it.</li>
<li>2023-09-21: The AI is out of service due to end of cloud server, contact [email protected] if you want to support it.</li>
<li>2022-06-05: Support white put move far away from existing move on first and second step.</li>
</div>

</div>
</body>
<script>
Expand Down Expand Up @@ -236,7 +288,7 @@
thinking = true;
$.ajax({
type: "GET",
url: "/",
url: "/next_step",
data: params,
datatype: "json",
success: function (data) {
Expand Down Expand Up @@ -314,5 +366,9 @@
});
}

// Update the statement of service end
// Get the current date


</script>
</html>

0 comments on commit 1e1188f

Please sign in to comment.