[Solved] Dev instance with nginx: topic preview not working

When clicking “New Topic” in my dev instance, I get the following errors in the console and the preview pane doesn’t work:

Uncaught SyntaxError: Unexpected token <										markdown-it-bundle.js:1
Error: Could not find module pretty-text/engines/discourse-markdown/helpers		discourse/lib/text:40 
    at missingModule (discourse-loader:134)
    at require (discourse-loader:149)
    at setup (pretty-text/engines/discourse-markdown-it:242)
    at buildOptions (pretty-text/pretty-text:100)
    at getOpts (discourse/lib/text:25)
    at cook (discourse/lib/text:30)
    at eval (discourse/lib/text:38)
    at tryCatch (ember:50180)
    at invokeCallback (ember:50195)
    at publish (ember:50163)

The second error then occurs each time I input a character in the text area.

I believe this problem was not occurring a few months back, but I’m not sure. I’m currently using v1.9.0.beta5 +90.

Because I run my dev instance behind a nginx reverse proxy, I’ve tried the solution proposed by @mr8 in here:

https://meta.discourse.org/t/discourse-preview-not-working/67584/36?u=jack2

It hasn’t solve the issue, but the error has changed. I now get:

GET https://127.0.0.1:3000/assets/markdown-it-bundle.js net::ERR_CONNECTION_CLOSED   jquery:9245 
Error: error                                                                         ember:19818 
    at unwrapErrorThrown (ember:33586)
    at errorFor (ember:33568)
    at onerrorDefault (ember:33558)
    at Object.trigger (ember:49836)
    at eval (ember:50737)
    at invokeWithOnError (ember:2197)
    at Queue.flush (ember:2256)
    at DeferredActionQueues.flush (ember:2380)
    at Backburner.end (ember:2450)
    at Backburner.run (ember:2564)
Uncaught promise:  {jqXHR: {…}, textStatus: "error", errorThrown: "error"}           (index):455 

Any idea?

(also, I’ve tried to switch my instance to “force https”, but it made no difference)

Have you tried disabling all your plugins to see if you still get the error?

Do you have your app.yml configured for https?

2 Likes

Thanks @mr8.

I’ve disabled all my plugins and seen no change.
I’m running a dev instance, so I believe there’s no app.yml file.

In the Chrome console, I see Discourse trying to load http://127.0.0.1:3000/assets/markdown-it-bundle.js. Of course, client-side, this url points to nothing.

This url comes from the fact that my nginx is configured like this:

server {
  ...
  server_name www.mydomain.org;
  ...
  location / {
    ...
    proxy_pass http://127.0.0.1:3000;
    ...
  }
}

i.e. http://127.0.0.1:3000/assets/markdown-it-bundle.js is an internal server-side url.

What am I missing?

You are missing the other proxy directives. You need all of these:

		# proxy_pass .....;
		proxy_set_header Host $http_host;
		proxy_http_version 1.1;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Proto $scheme;
		#proxy_set_header Client-IP "";
3 Likes

I’ve never used the dev instance, but it looks like discourse thinks your domain is http://127.0.0.1:3000 and serving the assets with that ‘domain’.

@riking, that did it, thanks a lot. Somewhere along the line I’d commented out my X-Forwarded-For line, for whatever reason.
Thanks also for your excellent link! There’re so many Discourse+nginx pages on this forum (and on the Internet), that it’s good to have a reference one.

4 Likes