When running a warp application using run
, it listens on all IP adresses.
For security reasons, I want to listen on localhost
only, handling remote access using a reverse proxy.
How do I need to call run
to only listen on a specific host/IP?
Note: This question intentionally shows no research effort as it was answered Q&A-Style.
run
itself can't do that. you need to userunSettings
:The
Settings
parameter you want to pass it contains the information about the hosts it listens on.The relevant type here is
HostPreference
. Although it allows you to specify different wildcards, includingIPv6Only
, we'll use theHost
constructor here.Based on this answer, I'll show a minimal example to listen on localhost only.
Note that accessors like
settingsHost
are marked deprecated, but the official documentation for warp 2.1.2.1 still shows an example usingsettingsTimeout
here.The currently accepted answer got broken by changes to conduit and/or warp. Warp no longer exports a
Host
constructor. But you don't need it, because theHostPreference
type supports the OverloadedStrings extension, so you can just use a string directly.This example also eliminates the deprecation warnings by switching to
setPort
andsetHost
.