I am working on my chat application project which is working fine in development.But when I am serving static file from server chat API is not working which fetch the chat list.It’s responding with a html template.Which is the html template from the dist folder.But the auth APIs at beginning are working in production build.Here is the folder structure-
.
└── Chat app/
├── Client
├── Server
├── .gitignore
├── Readme.md
├── package.lock.json
└── package.json
In development I am running server and client separately.
Here is how I am serving static file
`const __dirname1 = path.resolve();
app.use(express.static(path.join(__dirname1, "client/dist")));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname1, "client", "dist", "index.html"));
});`
In vite config I added proxy
`export default defineConfig({
plugins: [react()],
build: {},
server: {
proxy: {
"/api": {
target: "http://localhost:2000",
changeOrigin: true,
},
},
},
});`
At the beginning chat api was responding with status code 304 not modified and same html template.Then I did this to set cache control to no-store
app.use("/api/*", (req, res, next) => { res.set("Cache-Control", "no- store"); next(); });
I am using tanstack query for fetching chat list.As the auth API working by axios.I thought it’s a problem with tanstack query. Then I used used useEffect and axios to fetch the chat list.It’s still responding with the same response.
I am still learning.I will really appreciate the help with the issue.
jamshed_uddin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.