Workers for mta-sts not getting correct url

I created a worker to create the text output required for mta-sts and it stored the worker in the location So it responds to the url with the correct informtion. I made a custom domain mta-sts. and added a trigger mta-sts./* for the domain.I thought this would make it solve https://mta-sts-/.well-known/mta-sts.txt but it does not. What do I need to do to solve it so I can make it work

This URL returns an error.

the actual url is mta-sts-newkirk-engineering-com itaccounts-b05 workers dev .well-known mta-sts.txt and it returns the correct result however I need the same result when i enter mta-sts-newkirk-engineering com .well-known mta-sts.txt. Sorry for the time to respond however I could not work out how to enter url till i read post saying take out the dots and /.

Did you mean

For me this returns is not defined in the mta-sts worker

Are you able to share the code you are using?

As for this, use the Preformatted Text which is the </> icon in the post toolbar.

1 Like

yes that is what I am getting as well.

here is the code I hope

const stsPolicies = {
 `version: STSv1
 mode: testing
 mx: *
 max_age: 86400`
 const respHeaders = {
   "Content-Type": "text/plain;charset=UTF-8",
 addEventListener("fetch", event => {
 async function handleRequest(request) {
   let reqUrl = new URL(request.url)
   if (!stsPolicies.hasOwnProperty(reqUrl.hostname)) {
     return new Response(`${reqUrl.hostname} is not defined in the mta-sts worker\n`, {status: 500, headers: respHeaders})
   if (reqUrl.protocol === "https:" && reqUrl.pathname === "/.well-known/mta-sts.txt") {
     return new Response(stsPolicies[reqUrl.hostname] + "\n", {status: 200, headers: respHeaders})
   } else {
     reqUrl.protocol = "https:"
     reqUrl.pathname = "/.well-known/mta-sts.txt"
     return Response.redirect(reqUrl, 301)

I only get the correct answer whan I use the
that is where the worker is stored and I can’t seem to get it to the correct place or get it called when I use the worker even though I have the as a custom domain and a route of*

Once againsorry but I think I finally worked out how to include url and code.

Great you’ve figured it out.

!stsPolicies.hasOwnProperty(reqUrl.hostname) is failing because there is property in stsPolicies.

Thankyou. I changed the code to check against and now it is functioning as expected. I really apreciate your help. Thanks again

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.