H
Hono3mo ago
Junny

Route is cached. Can't clear it even after ending server.

I had a hono app running a route as such:
export const app = new Hono();
app.use(cors());
export default app;

const apiRoutes = app
.basePath("/api")
.route("/auth", authRoute)
.route("/posts", postRoute);

export type ApiRoutes = typeof apiRoutes;
export const app = new Hono();
app.use(cors());
export default app;

const apiRoutes = app
.basePath("/api")
.route("/auth", authRoute)
.route("/posts", postRoute);

export type ApiRoutes = typeof apiRoutes;
The postRoute is a standard json return which works fine. However, in the authRoute, the endpoint /authorize seems to be cached and never updates when I make changes to it. As a matter of fact, the endpoint is still accessible even after removing it from the first file provided above AND even after ending the server. Here is the snippet of this endpoint:
app.get("/authorize", (c) => {
const { SPOTIFY_CLIENT_ID, SPOTIFY_REDIRECT_URI } = process.env;

const scopes = encodeURIComponent(
["user-read-email", "user-read-private"].join(" ")
);
const authUrl =
`https://accounts.spotify.com/authorize?` +
`client_id=${SPOTIFY_CLIENT_ID}` +
`&response_type=code` +
`&redirect_uri=${SPOTIFY_REDIRECT_URI}` +
`&scope=${scopes}` +
`&show_dialog=true`;

return c.redirect(authUrl, 301);
});
app.get("/authorize", (c) => {
const { SPOTIFY_CLIENT_ID, SPOTIFY_REDIRECT_URI } = process.env;

const scopes = encodeURIComponent(
["user-read-email", "user-read-private"].join(" ")
);
const authUrl =
`https://accounts.spotify.com/authorize?` +
`client_id=${SPOTIFY_CLIENT_ID}` +
`&response_type=code` +
`&redirect_uri=${SPOTIFY_REDIRECT_URI}` +
`&scope=${scopes}` +
`&show_dialog=true`;

return c.redirect(authUrl, 301);
});
This endpoint is supposed to redirect to Spotify auth (which did work until I wanted to make some changes). I've been trying to fix this for hours. Please help a brother out.
1 Reply
Junny
JunnyOP3mo ago
Nevermind, I found the solution! Apparently sending back a status of 301 will cache the redirect since it indicates a permanent redirection of a URL. Instead, I sent back a 302 which indicates the move is temporary. Source: https://stackoverflow.com/questions/8136315/how-to-avoid-browser-redirect-caching

Did you find this page helpful?