Adding robots.txt to Expo for web

31 Views Asked by At

I'm building across native and web with Expo 49. For the web version, I need to add a /robots.txt route, and other similar paths.

In my /app directory, I tried adding an escaped path to ensure it resolves with the .txt:

/app/robots[.]txt.tsx

But it didn't work. Expo redirects to [...missing].tsx.

And of course this works: /app/robots.tsx

But then it resolves to the path: /robots which is not correct.

Is there another way to do this? If not allowing the path as robots.txt, then adding the .txt in the static web build?

1

There are 1 best solutions below

0
alyx On BEST ANSWER

I resolved this by creating a public directory in the root and added robots.txt there, and then built the web version and served it:

npx expo export -p web
npx serve dist

Now robots.txt is available at localhost:3000/robots.txt