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 .itaccounts-b05.workers.dev. So it responds to the url https://mta-sts-.itaccounts-b05.workers.dev/.well-known/mta-sts.txt 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 https://mta-sts.newkirk-engineering.com/.well-known/mta-sts.txt?

For me this returns

mta-sts.newkirk-engineering.com 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 = {
   "mta-sts-newkirk-engineering-com.itaccounts-b05.workers.dev":
 `version: STSv1
 mode: testing
 mx: *.mail.protection.outlook.com
 max_age: 86400`
 }
 
 const respHeaders = {
   "Content-Type": "text/plain;charset=UTF-8",
 }
 
 addEventListener("fetch", event => {
   event.respondWith(handleRequest(event.request))
 })
 
 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
mta-sts-newkirk-engineering-com.itaccounts-b05.workers.dev/.well-known/mta-sts.txt
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 mta-sts.newkirk-engineering.com as a custom domain and a route of mta-sts.newkirk-engineering.com/*

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 mta-sts.newkirk-engineering.com property in stsPolicies.

Thankyou. I changed the code to check against mta-sts.newkirk-engineering.com 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.