Using Dart as a full-stack language
For dynamic content, we could use Dart's HTTP server, but we probably wouldn't expose it directly to the Internet and rather put in behind a reverse proxy.
If you really wanted to expose your server to anyone, you need to tell the HTTP server to accept connections from all IPs with ANY_IP_V4
instead of LOOPBACK_IP_V4
:
var addr = InternetAddress.ANY_IP_V4
This also applies to WebSockets servers.
Accessing Dart servers via Apache or nginx reverse proxies lets you stay with LOOPBACK_IP_V4
(127.0.0.1
, aka localhost), which is generally safer.
Using Apache as a proxy for the Dart HTTP server
As we said, we can use Apache to serve all static content and proxy all nonstatic requests to the Dart HTTP server. You can modify your hosts
file to point dart.localhost
to 127.0.0.1
if you're already using virtual hosts on your computer and add a new directive to the Apache configuration:
<VirtualHost *:80> DocumentRoot "/project/path/Chapter_07_route_http_server/public...