a year ago
I have a very simple express app, I have it in a monorepo just to test some stuff, it builds fine, it starts fine, but I get the "application failed to respond" error when going to it on the provided domain
I'm logging all traffic, and I can see that I'm not getting any when navigating to the domain
I've tested the build locally, and it builds and starts just fine
Any ideas?
import express from "express";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
const PORT = 3000;
app.use(express.static(path.join(__dirname, "dist")));
app.get("*", (req, res) => {
console.log("Request made: ", req.path);
res.sendFile(path.join(__dirname, "dist", "index.html"));
});
app
.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
})
.on("error", (err) => {
console.log(`Error: ${err}`);
process.exit(1);
});9 Replies
a year ago
Each application will be assigned a random port number. Unless you specify. Your code above sets the port variable. You would want to do something like
const PORT = process.env.PORT || 3000;
Then when you deploy, it will use the railway provided port, which will automatically display in the selection when you add a domain
a year ago
If you want to continue using 3000 as your port, you must set a PORT environment variable as 3000 in your service
a year ago
No problem
