Support Forums

How to redirect any user who enter to my js folder to 404 page

Hi i Created my domain: https://mouktarart.com in netlify the site is deployed from github
i add to my netlify.toml this redirect:
from = “/js/*”
status = 404
to = “/404.html”

but its not working users can access my github js files paths . how can i secure my code?

When I visit https://mouktarart.com/js/ I see this

Of course, I can open dev tools and see this

It is an asset downloaded by the browser to run/render element(s) on your site.

IMHO, you shouldn’t try to hide it. That stifles learning.

You could obfuscate it to make it harder for people to pull apart. But I don’t think you should do that either. Share, let other people learn from what you have done.

1 Like

I agree with you the learning part, ok but if have secrets i should use env variables i guess can you point me to the best practice or a place to learn from?

Yes, if you have private API keys for a payment gateway, database, etc. then you could/would use environment variables and serverless functions and not have these secrets exposed to the client and only the response data.

As for learning, have a look at the function examples and also at Jamstack Explorers

1 Like