Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploying Niltalk as a Microservice in a Subdirectory #32

Closed
ohmykreee opened this issue Apr 8, 2023 · 3 comments
Closed

Deploying Niltalk as a Microservice in a Subdirectory #32

ohmykreee opened this issue Apr 8, 2023 · 3 comments
Labels

Comments

@ohmykreee
Copy link

I am attempting to deploy the Niltalk application on a subdirectory as a micro service, but I am encountering several issues.

Specifically, I have set the root_url in the config.toml file to https://example.site/chat, and I have set up a reverse proxy in Nginx to point to the application:

    location /chat/ {

      proxy_set_header        Host $host;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        X-Forwarded-Proto $scheme;
      proxy_set_header        Connection $http_connection;
      # proxy_set_header        X-NginX-Proxy true;

      proxy_pass          http://localhost:9000/;
      proxy_read_timeout  120;
    }

When I access https://example.site/chat, my browser is reporting multiple errors related to missing resources:

vue.min.js:1  Failed to load resource: the server responded with a status of 404 (https://example.site/vue.min.js)
client.js:1 Failed to load resource: the server responded with a status of 404 (https://example.site/client.js)
app.js:1 Failed to load resource: the server responded with a status of 404 (https://example.site/app.js)
logo.png:1  Failed to load resource: the server responded with a status of 404 (https://example.site/logo.png)
chat.png:1 Failed to load resource: the server responded with a status of 404 (https://example.site/chat.png)
style.css:1 Failed to load resource: the server responded with a status of 404 (https://example.site/style.css)

I tried using use custom static files and modify some files like template/base.html to reference them, but this approach only made things worse:

<script src="./static/vue.min.js"></script>
<script src="./static/client.js"></script>
<script src="./static/app.js"></script>

Is there a way to host Niltalk in a subdirectory as a microservice?

@ohmykreee ohmykreee changed the title Sub path deploy support Deploying Niltalk as a Microservice in a Subdirectory Apr 8, 2023
@knadh
Copy link
Owner

knadh commented Apr 9, 2023

In your custom static templates, revert everything to the default value, and try adding this tag right after the <title>...</title> tag.

<base href="{{ .Config.RootURL }}">

@knadh knadh added the question label Apr 9, 2023
@ohmykreee
Copy link
Author

Thank you for your suggestion.

I have reverted to the default value and added the <base> tag as you recommended. Here's a partial snippet of my template/base.html file to show the changes I made:

{{ define "header" }}
<!DOCTYPE html>
<html lang="en">
<head>
        <title>{{ if .Data.Title }} {{ .Data.Title }} - Niltalk {{ else }}Niltalk &mdash; Instant disposable chat rooms{{ end }}</title>
        <base href="{{ .Config.RootURL }}">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        ...

However, I'm still encountering the same error when using custom static files to launch the application. Here are some screenshots of the errors I received in my browser:
image
image
image

Please let me know if there's anything else I could try. Thank you for your assistance.

@knadh
Copy link
Owner

knadh commented Apr 10, 2023

Ah, my bad. This would require the handlers that are registered in Go program to also be aware of the sub-path, which isn't possible out of the box.

You could look at Nginx rewrite rules to strip the subpaths before proxying the requests to the backend.

@knadh knadh closed this as completed Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants