OvidijusParsiunas / deep-chat

Fully customizable AI chatbot component for your website
https://deepchat.dev
MIT License
1.26k stars 170 forks source link

Deploy deep chatbot on website with Flask on a local HTTP Apache server with Windows 11 #132

Closed calypset closed 4 months ago

calypset commented 4 months ago

Anyone tried deployment over a website with Flask on a local HTTP Apache server? I am able to have the request='{"url": "http://localhost:8080/chat-stream"} serving locally but as soon as on another computer even on same network it doesn't work and I receive the following error: deepChat.bundle.js:1 POST http://localhost:8080/chat-stream net::ERR_CONNECTION_REFUSED, on inspect with chrome.

Unsure if issue with CORS or WSGI or else.

OvidijusParsiunas commented 4 months ago

Hi @calypset.

The error you are getting is hinting that the fetch request from the browser is not making it to your server and I don't believe has much to do with Deep Chat itself.

As an experiment, in the machine that is having the problem - I would recommend you to open up the developer console in Chrome and attempt to execute the fetch('http://localhost:8080/chat-stream'); code. If you get the net::ERR_CONNECTION_REFUSED error, then the browser is simply failing to connect/reach your server:

image

If you get the 500 (INTERNAL SERVER ERROR error, then the browser can connect to the server, but some more configuration (such as headers) may be required:

image

To troubleshoot this properly, I would recommend using a tool such as Postman or its browser extension to test if your server is reachable from your machine/browser.

calypset commented 4 months ago

On external network:

In Chrome I get this:

image

In Firefox I get this:

image

Please note: port and chat mode are different from above for troubleshooting purposes.

OvidijusParsiunas commented 4 months ago

Interesting, perhaps FireFox is showing a more fine-grained response. I personally use Postman for troubleshooting these things, so it may provide even more details. But if it is a CORS error, I would guess you need to check your CORS policy in your server :/

calypset commented 4 months ago

I have solved the problem. Finally, WSGI, the Python App and the HTTPD conf file on Apache were misconfigured. CORS was not really of the matter, but some inaccurate error from Firefox.

The chat message was not reaching out to the server from outside the network. What helped most to troubleshoot WSGI is adding the following to the virtualHost settings for the app in httdp.conf:

WSGIScriptAlias / "/path/to/maypp/myapp.wsgi" application-group=%{GLOBAL} and LogLevel info

Making the script global allows you to follow errors in the Apache error log file because the App is started upon starting the HTTP server and the log level gives more info. Also had to install the SSL certificates for Flask. Setting up mod_wsgi, Flask and the virtualhost are like, not for the faint of heart.

calypset commented 4 months ago

Closed

OvidijusParsiunas commented 4 months ago

I'm happy you got it sorted @calypset and thankyou for posting your solution!