I’ve deployed my Next.js application in AWS Amplify. Everything is okay except I can’t access the url search params on the api routes of my application.
export default async function handler(req, res) {
// Check for secret to confirm this is a valid request
if (req.query.secret != process.env.NEXT_PRIVATE_REVALIDATION_KEY) {
return res.status(401).json({ message: 'Invalid token' })
}
try {
// validate homepage
} catch (err) {
return res.status(500).send('Error revalidating')
}
}
I’m trying to make a get request to the following endpoint.
https://example.com/api/revalidate/?secret=example-validation-key&slug=homepage
But the server responds as if there is no token. It works if I deploy the app on ec2.
Here is the rewrite settings from my Amplify app.
Source | Destination | Type |
---|---|---|
/<*> | /index.html | 404 (Rewrite) |
https://example.com | https://www.example.com | 302 (Redirect – Temporary) |
I tried to put a ‘/’ before the query params as this post suggest but still no luck.