'Deploying react + express to heroku getting dns error
so ive been trying to switch my client side react SPA to use express server and set up a quick server file that is working in local but when i deploy to heroku the page cleary starts to load then it just throws a dns error. Ive tried all the express tutorials i could find online without any luck. Server code:
const express = require("express")
const path = require("path");
const app = express()
const fs = require("fs");
// use the express-static middleware
app.use(express.static("public",{index: false}))
app.get("*", async function (req, res) {
var asd = path.join(__dirname,"public/index.html")
fs.readFile(asd, "utf8", function (err, data) {
if (err) {
return console.log(err);
}
console.log(data)
res.send(data);
})
//res.sendFile(asd);
})
// start the server listening for requests
app.listen(process.env.PORT || 3001,
() => console.log("Server is running on port " + process.env.PORT));
tried it with simply res.sendFile but that didnt work either. the public folder just contains my React clients "build" folder copied over. Really weird how everything runs locally, plus the react site starts to load then crashes without any logs or errors, it just returns "(failed) net::ERR_NAME_NOT_RESOLVED" heroku even logs 200 on the incoming request.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
