瀏覽代碼

Allow running the app behind a reverse proxy (#57)

* change url to hide app behind a relative path

* pass some of ther server configuration through to the client

* serve static files and connect to socket.io correctly when a URL Prefix is set

* Revert the changes to opengraph meta tags

opengraph meta tags need to be absolute URLs

* Remove unused commented-out code

* fix background.png url

* use prefix path for open graph metadata

* Revert changes using server side url modifications

* get open graph and socket.io url from request url / window.location

* remove debug console.log

* Fix favicon when not running under "/"

* Add proxying instructions to the README

Co-authored-by: Laurent Mazet <mazet@softndesign.org>
Co-authored-by: ophir <pere.jobs@gmail.com>
dev_h
finnboeger 5 年之前
父節點
當前提交
0f0b333335
沒有連結到貢獻者的電子郵件帳戶。
共有 7 個檔案被更改,包括 36 行新增27 行删除
  1. 6
    0
      README.md
  2. 20
    19
      client-data/board.html
  3. 1
    1
      client-data/index.css
  4. 3
    3
      client-data/index.html
  5. 1
    0
      client-data/js/board.js
  6. 3
    3
      server/server.js
  7. 2
    1
      server/templating.js

+ 6
- 0
README.md 查看文件

@@ -66,6 +66,12 @@ PORT=5001 npm start
66 66
 
67 67
 This will run WBO directly on your machine, on port 5001, without any isolation from the other services.
68 68
 
69
+### Running WBO on a subfolder
70
+
71
+By default, WBO launches his own web server and serves all of its content at the root of the server (on `/`).
72
+If you want to make the server accessible with a different path like https://your.domain.com/wbo/ you have to setup a reverse proxy.
73
+See instructions on our Wiki about [how to setup a reverse proxy for WBO](https://github.com/lovasoa/whitebophir/wiki/Setup-behind-Reverse-Proxies).
74
+
69 75
 ## Troubleshooting
70 76
 
71 77
 If you experience an issue or want to propose a new feature in WBO, please [open a github issue](https://github.com/lovasoa/whitebophir/issues/new).

+ 20
- 19
client-data/board.html 查看文件

@@ -5,19 +5,20 @@
5 5
 	<meta charset="utf-8" />
6 6
 	<title>{{board}} | WBO | {{translations.collaborative_whiteboard}}</title>
7 7
 	<meta name="viewport" content="width=device-width, initial-scale=1" />
8
-	<link rel="stylesheet" type="text/css" href="board.css" />
9
-	<script src="/socket.io/socket.io.js"></script>
8
+	<link rel="stylesheet" type="text/css" href="../board.css" />
9
+	<script src="../socket.io/socket.io.js"></script>
10 10
 	<meta name="description" content="{{translations.tagline}}'" />
11 11
 	<meta name="keywords"
12 12
 		content="{{translations.collaborative_whiteboard}},online,draw,paint,shared,realtime,wbo,whitebophir" />
13
-	<link rel="apple-touch-icon" href="/favicon.svg">
13
+	<link rel="apple-touch-icon" href="../favicon.svg">
14
+	<link rel="icon" type="image/x-icon" sizes="16x16" href="../favicon.ico">
14 15
 	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0" />
15 16
 	<meta property="og:title" content="{{board}} board on WBO" />
16
-	<meta property="og:url" content="{{baseUrl}}/boards/{{boardUriComponent}}" />
17
-	<meta property="og:image" content="{{baseUrl}}/preview/{{boardUriComponent}}" />
18
-	<link rel="canonical" href="{{baseUrl}}/boards/{{boardUriComponent}}?lang={{language}}" />
17
+ 	<meta property="og:url" content="{{baseUrl}}/boards/{{boardUriComponent}}" />
18
+ 	<meta property="og:image" content="{{baseUrl}}/preview/{{boardUriComponent}}" />
19
+	<link rel="canonical" href="{{boardUriComponent}}?lang={{language}}" />
19 20
 	{{#languages}}
20
-	<link rel="alternate" hreflang="{{.}}" href="{{../baseUrl}}/boards/{{../boardUriComponent}}?lang={{.}}" />
21
+	<link rel="alternate" hreflang="{{.}}" href="{{../boardUriComponent}}?lang={{.}}" />
21 22
 	{{/languages}}
22 23
 </head>
23 24
 
@@ -78,17 +79,17 @@
78 79
 
79 80
 
80 81
 	<script type="application/json" id="translations">{{{json translations}}}</script>
81
-	<script src="js/path-data-polyfill.js"></script>
82
-	<script src="js/minitpl.js"></script>
83
-	<script src="js/board.js"></script>
84
-	<script src="tools/pencil/pencil.js"></script>
85
-	<script src="tools/line/line.js"></script>
86
-	<script src="tools/rect/rect.js"></script>
87
-	<script src="tools/text/text.js"></script>
88
-	<script src="tools/eraser/eraser.js"></script>
89
-	<script src="tools/hand/hand.js"></script>
90
-	<script src="tools/zoom/zoom.js"></script>
91
-	<script src="/js/canvascolor/canvascolor.min.js"></script>
82
+	<script src="../js/path-data-polyfill.js"></script>
83
+	<script src="../js/minitpl.js"></script>
84
+	<script src="../js/board.js"></script>
85
+	<script src="../tools/pencil/pencil.js"></script>
86
+	<script src="../tools/line/line.js"></script>
87
+	<script src="../tools/rect/rect.js"></script>
88
+	<script src="../tools/text/text.js"></script>
89
+	<script src="../tools/eraser/eraser.js"></script>
90
+	<script src="../tools/hand/hand.js"></script>
91
+	<script src="../tools/zoom/zoom.js"></script>
92
+	<script src="../js/canvascolor/canvascolor.min.js"></script>
92 93
 </body>
93 94
 
94
-</html>
95
+</html>

+ 1
- 1
client-data/index.css 查看文件

@@ -1,5 +1,5 @@
1 1
 html {
2
-	background: linear-gradient(135deg, #c4dfffa0, transparent), url(/background.png);
2
+	background: linear-gradient(135deg, #c4dfffa0, transparent), url(background.png);
3 3
 	width:100%;
4 4
 	height: 100%;
5 5
 	margin:0;

+ 3
- 3
client-data/index.html 查看文件

@@ -44,12 +44,12 @@
44 44
 
45 45
 		<div>
46 46
 			<p>{{{translations.public_board_description}}}</p>
47
-			<a href="/boards/anonymous" class="wbo-button">{{{translations.open_public_board}}}</a>
47
+			<a href="boards/anonymous" class="wbo-button">{{{translations.open_public_board}}}</a>
48 48
 		</div>
49 49
 
50 50
 		<div>
51 51
 			<p>{{{translations.private_board_description}}}</p>
52
-			<a href="/random" class="wbo-button">{{{translations.create_private_board}}}</a>
52
+			<a href="random" class="wbo-button">{{{translations.create_private_board}}}</a>
53 53
 		</div>
54 54
 
55 55
 		<div>
@@ -68,4 +68,4 @@
68 68
 	</footer>
69 69
 </body>
70 70
 
71
-</html>
71
+</html>

+ 1
- 0
client-data/js/board.js 查看文件

@@ -55,6 +55,7 @@ Tools.connect = function() {
55 55
 
56 56
 
57 57
 	this.socket = io.connect('', {
58
+		"path": window.location.pathname.split("/boards/")[0] + "/socket.io",
58 59
 		"reconnection": true,
59 60
 		"reconnectionDelay": 100, //Make the xhr connections as fast as possible
60 61
 		"timeout": 1000 * 60 * 20 // Timeout after 20 minutes

+ 3
- 3
server/server.js 查看文件

@@ -83,7 +83,7 @@ function handleRequest(request, response) {
83 83
 			// If there is no dot and no directory, parts[1] is the board name
84 84
 			boardTemplate.serve(request, response);
85 85
 		} else { // Else, it's a resource
86
-			request.url = "/" + parts.slice(1).join('/');
86
+			request.url = parts.slice(1).join('/');
87 87
 			fileserver(request, response, serveError(request, response));
88 88
 		}
89 89
 	} else if (parts[0] === "download") {
@@ -121,7 +121,7 @@ function handleRequest(request, response) {
121 121
 		});
122 122
 	} else if (parts[0] === "random") {
123 123
 		var name = crypto.randomBytes(32).toString('base64').replace(/[^\w]/g, '-');
124
-		response.writeHead(307, { 'Location': '/boards/' + name });
124
+		response.writeHead(307, { 'Location': 'boards/' + name });
125 125
 		response.end(name);
126 126
 
127 127
 	} else if (parts[0] === "") { // Index page
@@ -133,4 +133,4 @@ function handleRequest(request, response) {
133 133
 }
134 134
 
135 135
 
136
-module.exports = app;
136
+module.exports = app;

+ 2
- 1
server/templating.js 查看文件

@@ -31,7 +31,8 @@ class Template {
31 31
         const accept_languages = parsedUrl.query.lang || request.headers['accept-language'];
32 32
         const language = accept_language_parser.pick(languages, accept_languages) || 'en';
33 33
         const translations = TRANSLATIONS[language] || {};
34
-        const baseUrl = findBaseUrl(request);
34
+        const prefix = request.url.split("/boards/")[0].substr(1);
35
+        const baseUrl = findBaseUrl(request) + (prefix ? prefix + "/" : "");
35 36
         return { baseUrl, languages, language, translations };
36 37
     }
37 38
     serve(request, response) {

Loading…
取消
儲存