#Creating a json endpoint with SSR enabled - Not random every time...

6 messages · Page 1 of 1 (latest)

hidden whale
#

Hi there,

I'm mucking around with the idea of using astro to create a simple API endpoint that could be consumed by another service.

I've enabled SSR and successfully deploying to Netlify.

As a proof of concept, I'm looking to get a random number returned in JSON format every time I visit the url.

However, when I visit the endpoint URL, I'm getting json back but it looks like it's not using SSR and only generating on build.

I have SSR enabled in the config file
I have a js file that exports a string with a random number
When I visit this endpoint, it's a new number on every build NOT every time I visit like I'd expect.

https://ssr-test-sean.netlify.app/myendpoint.json

Am I misunderstanding something or is there some cache happening with Netlify that I need to stop?
Thanks

shadow crescent
#

I’d try moving the declaration of randNum inside the get function instead of declaring at the top level of the file.

golden topaz
#

I think it might not be working because the file name is ‘.json.js’, does it work if it is just ‘.js’?

hidden whale
hidden whale
golden topaz