Homepage    |    GitHub    |    API    |    FAQ

[joplin-server] Changeable root-context?

Hi guys,

I do have specific issue related to lighttpd 1.4 bug. Unlike all other webservers on whole world, Lighttpd proxying not only request, but also the context for what is set.

So if you ex. set proxying "/joplin" --> xxx.xxx.xxx.xxx:22300 it will forward it as xxx.xxx.xxx.xxx:22300/joplin

And now you probably get the point - I have no option to change it (well, the only way could be forward whole root context "/" on domain). I did tried workaround described there, but with no luck at all. Beside it's really bad.

Unfortunately, it's router, where I can't run another webserver (like Apache or Nginx) without lot of troubles, so this is not the way as well.

It would help me a lot, if there could be some option for setting of listening path (ex. :/joplin/api/....) Is there some option for? Ex manage it by some script/command in container directly using Dockerfile or something... any idea?

I don't quite understand the issue, but can't you get it working using the env variables like APP_BASE_URL or API_BASE_URL?

APP_BASE_URL definitely not, as it sets where expects user coming from, but doesn't change app context itself.

So, in case of ex. /login app in docker instance listen on xxxxxx:22300/login and I need, that root context of app would be xxxxx:22300/joplin/login instead.

APP_BASE_URL is not working this way, unfortunately. It's bit like "link of home page", where it should go when you want to visit home page. However that API_BASE_URL looks promising... is it really for all context, or just for /api/....?

It's the API base URL that's publicly exposed, the part that goes before /api.

I tried to set it as following, but not luck:

APP_BASE_URL=https://<server>/joplin
API_BASE_URL=/joplin
APP_PORT=22300
app_1  | 2021-07-22 20:03:22: App: Call this for testing: `curl https://<server>/joplin/api/ping`
app_1  | 2021-07-22 20:03:22: ShareService: Maintenance completed in 23ms
// call the curl https://<server>/joplin/api/ping
app_1  | 2021-07-22 20:03:35: [error] App: 404: GET /joplin/api/ping : Path not found: joplin/api/ping
app_1  | 2021-07-22 20:03:35: App: GET /joplin/api/ping (9ms)
app_1  |
app_1  |   TypeError: Cannot read property 'owner' of null
app_1  |       at MustacheService.<anonymous> (/home/joplin/packages/server/src/services/MustacheService.ts:122:55)
app_1  |       at Generator.next (<anonymous>)
app_1  |       at /home/joplin/packages/server/dist/services/MustacheService.js:8:71
app_1  |       at new Promise (<anonymous>)
app_1  |       at __awaiter (/home/joplin/packages/server/dist/services/MustacheService.js:4:12)
app_1  |       at MustacheService.renderView (/home/joplin/packages/server/dist/services/MustacheService.js:86:16)
app_1  |       at /home/joplin/packages/server/src/middleware/routeHandler.ts:54:52
app_1  |       at Generator.throw (<anonymous>)
app_1  |       at rejected (/home/joplin/packages/server/dist/middleware/routeHandler.js:6:65)
app_1  |

maybe it's some new option? (i'm using image: joplin/server:latest)

ok, i've change conf to get rid of proxy, just for sure, and looks it indeed ignores setup *_BASE_URL:

APP_BASE_URL=http://192.168.1.3:22300/joplin
API_BASE_URL=http://192.168.1.3:22300/joplin
APP_PORT=22300

where the curls direct to /api/... works still fine, /joplin/api/... doesn't.

~$ curl http://192.168.1.3:22300/api/ping
{"status":"ok","message":"Joplin Server is running"}
~$ curl http://192.168.1.3:22300/joplin/api/ping
Internal Server Error

and it definitely accepts the variables:

app_1  | 2021-07-22 20:26:26: App: Starting server v2.1.1 (prod) on port 22300 and PID 27...
app_1  | 2021-07-22 20:26:26: App: Running in Docker: true
app_1  | 2021-07-22 20:26:26: App: Public base URL: http://192.168.1.3:22300/joplin
app_1  | 2021-07-22 20:26:26: App: API base URL: http://192.168.1.3:22300/joplin
app_1  | 2021-07-22 20:26:26: App: User content base URL: http://192.168.1.3:22300/joplin

will yet try to go with some newer version yet....

Well,

app_1  | 2021-07-22 20:48:32: App: Starting server v2.2.7 (prod) on port 22300 and PID 27...
app_1  | 2021-07-22 20:48:32: App: Running in Docker: true
app_1  | 2021-07-22 20:48:32: App: Public base URL: http://192.168.1.3:22300/joplin
app_1  | 2021-07-22 20:48:32: App: API base URL: http://192.168.1.3:22300/joplin
app_1  | 2021-07-22 20:48:32: App: User content base URL: http://192.168.1.3:22300/joplin

nad same story, unfortunately. The only difference is, that I do have nice error page now, instead of just error mesage as before :slight_smile:

panelacek@SynStorage:~$ curl -v http://192.168.1.3:22300/joplin/api/ping
> GET /joplin/api/ping HTTP/1.1
> Host: 192.168.1.3:22300
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Vary: Origin
< Content-Type: text/html
< Content-Length: 1848
< Date: Thu, 22 Jul 2021 20:54:04 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
<
<!doctype html>
<html>
<head>
	<title>Joplin Server - Error</title>
	<meta charset="utf-8">
	<link rel="stylesheet" href="http://192.168.1.3:22300/joplin/css/bulma.min.css" crossorigin="anonymous">
		<!-- <link rel="stylesheet" href="http://192.168.1.3:22300/joplin/css/bulma-prefers-dark.min.css" crossorigin="anonymous"> -->
	<link rel="stylesheet" href="http://192.168.1.3:22300/joplin/css/main.css" crossorigin="anonymous">
	<link rel="stylesheet" href="http://192.168.1.3:22300/joplin/css/fontawesome/css/all.min.css" crossorigin="anonymous">
	<script src="http://192.168.1.3:22300/joplin/js/jquery.min.js"></script>
	<script src="http://192.168.1.3:22300/joplin/js/main.js"></script>
</head>
	<body class="page-error">
		<main class="main">
			<div class="container">

				<script>
					onDocumentReady(function() {
						const buttons = document.getElementsByClassName('close-notification-button');

						for (const button of buttons) {
							button.addEventListener('click', function(event) {
								const closeUrl = button.dataset.closeUrl;
								const notificationId = button.dataset.id;
								fetch(closeUrl, {
									method: 'PATCH',
									headers: { 'Content-Type': 'application/json' },
									body: JSON.stringify({
										read: 1,
									}),
								});

								document.getElementById('notification-' + notificationId).style.display = 'none';
							});
						}
					});
				</script>				<section class="section">
	<div class="container">
		<div class="notification is-danger">
			Path not found: joplin&#x2F;api&#x2F;ping
		</div>
			<p><a href="http://192.168.1.3:22300/joplin/login">Go to login page</a></p>
	</div>
</div>
			</div>
		</main>
		<div class="footer">
			<div class="content has-text-centered">
				Joplin Server 2.2.7, copyright (C) 2021 Laurent Cozic.
			</div>
		</div>	</body>
</html>panelacek@SynStorage:~$ curl -v http://192.168.1.3:22300/api/ping
> GET /api/ping HTTP/1.1
> Host: 192.168.1.3:22300
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Vary: Origin
< Content-Type: application/json; charset=utf-8
< Content-Length: 52
< Date: Thu, 22 Jul 2021 20:54:35 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
<
{"status":"ok","message":"Joplin Server is running"}
panelacek@SynStorage:~$

based on all path in href, looks it's actually expects /joplin/ context, but somehow, application is not deployed to it.

Should I create ticket on github?

If I can be completely honest I don't understand anything about what you're doing, so I'm not sure a GitHub ticket would help. Perhaps it's because I don't know lighthttpd or something.

ok, will try to explain more detaily:

The main point is, that I need somehow configure the server the way it will response on some custom context (base url) other, then /.
By default, you can access server by "/" path (ex. /api/... or /login). That is the way how it is working now. BUT - unfortunately, I need to be able to set server the way, it actually listen on, for example /joplin/api/... or /joplin/login etc...

And it's because lighttpd proxy is stupid the way, that if I set proxy /joplin, it instead of calling "/" on target server, it does /joplin as well.
so, for example when i set proxyPass for "/foo":
http://host.com/foo/api/ping will proxy to backend as http://local.host/foo/api/ping (BUT it's not possible to set up the way it will do http://local.host/api/ping)

Is it makes sense now?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.