How to send the ads.txt file correctly using Fastify?
- Dominant language
- No language data
- Stars
- 68
- Forks
- 8
- Avg merge
- 11h 2m
- Merged PRs (30d)
- 2
Description
## 💬
Hello!
I need to send a file called ads.txt so that Google AdSense can work on my website!
I tried it this way first:
```javascript
{
method:'GET',
url:'/ads.txt',
handler: async function (req, reply) {
reply.type('text/plain; charset=utf-8')
reply.send("google.com, pub-0000000, DIRECT, f00000000");
}
},
```
When I open the URL in the browser, it appears normal! But Google doesn't recognize that the file exists, even though the data is correct! So I tried another way:
```javascript
handler: async function (req, reply) {
const stream = fs.createReadStream('../public/ads.txt', 'utf8');
reply.type('text/plain').send(stream);
}
```
When I check the URL, only a blank page appears! How can I resolve this with Fastify?
These data need to appear for Google to correctly serve the ads!
Thank you in advance.
## Your Environment
- *node version*: 20
- *fastify version*: >=^4.17.0
- *os*: Linux Ubuntu
- *any other relevant information*: Nginx reverse proxy
Contributor guide
Assessment
This issue has not been assessed yet.