Fresh migrating from serveTls
In my
main.ts
file for Fresh I have some code I borrowed from source a few minor versions ago to serve HTTPS content when running on localhost. It looks like so
This is working, but serveTls
is marked deprecated in favor of Deno.serve
. However, Deno.serve
takes a single handler argument, not a handler and a config.
How might I go about migrating to Deno.serve
here? Thanks!4 Replies
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the code snippet you've provided, I can offer some general advice.
The
serveTls
function is indeed deprecated, and you should now use Deno.serve
to create a TLS server. The Deno.serve
function has a different API compared to serveTls
. To use Deno.serve
with TLS, you would need to pass the TLS options within the options object, like so:
Please note that the above code is a general example and not based on the Deno documentation. You should double-check the accuracy of this advice and consult the latest Deno API documentation or other resources for the most up-to-date information on using Deno.serve
with TLS.
In your specific case, you would need to adapt the ServerContext
and its handler to work with Deno.serve
. The ServerContext
should provide a handler function that you can pass directly to Deno.serve
. If the ServerContext
's handler method returns a function compatible with Deno.serve
, you can use it like this:
Again, please verify this with the current Deno APIs and the Fresh framework documentation to ensurecompatibility.
@rabbit_rabbit The way
Deno.serve
works is that it will serve via HTTPS when you give it a cert + key and won't if you don't. Since Fresh uses Deno.serve
already under the hood, you can simplify your code to something like this:
Thanks @marvinh. ! I tried that and it's still serving HTTP. For a cleaner test to ensure it's not an issue with environment variables I cleared some of the other stuff, so here's my attempt
where I see