help with 503 error code

Hello! I have a nest.js and postgres app on Railway We integrated stripe to manage the payments. Every time a user buys a ticket is redirected to a stripe payment gateway (out of the website domain) On the backend we have a webhook listening for the stripe payment process to complete. We have a webhook endpoint listening but it appears the request doesn't go through while running on Railway (works fine on local though) Question: How to get the webhook request my railway app to go through
33 Replies
Percy
Percy2y ago
Project ID: N/A
Percy
Percy2y ago
You can use the railway provided variable RAILWAY_STATIC_URL in code to register your webhook endpoint.
⚠️ experimental feature
Brody
Brody2y ago
where do you register this webhook?
VRBaller
VRBallerOP2y ago
It's an endpoint in our app. /payments/webhook
Brody
Brody2y ago
yes but where do you tell stripe to call that endpoint?
VRBaller
VRBallerOP2y ago
Ah, Stripe has https://dashboard.stripe.com/test/webhooks. It's registered there
Brody
Brody2y ago
screenshot please
VRBaller
VRBallerOP2y ago
Brody
Brody2y ago
okay looks fine now show me the bit of code that handles that endpoint
VRBaller
VRBallerOP2y ago
@Controller('payments')
export class StripeController {
private readonly logger = new Logger(StripeController.name);

constructor(
private readonly prisma: PrismaService,
private configService: ConfigService,
private stripeService: StripeService,
) {}

@Post('webhook')
async handleStripeWebhook(
@Req() req: RawBodyRequest<Request>,
@Res() res: Response,
) {
console.log('webhook-stripe-controller');
@Controller('payments')
export class StripeController {
private readonly logger = new Logger(StripeController.name);

constructor(
private readonly prisma: PrismaService,
private configService: ConfigService,
private stripeService: StripeService,
) {}

@Post('webhook')
async handleStripeWebhook(
@Req() req: RawBodyRequest<Request>,
@Res() res: Response,
) {
console.log('webhook-stripe-controller');
Brody
Brody2y ago
what language is that
VRBaller
VRBallerOP2y ago
Typescript
Brody
Brody2y ago
looks gross
VRBaller
VRBallerOP2y ago
... That makes you look bad ngl Actually works quite well look up nest.js
Brody
Brody2y ago
im not saying your code is gross anyway
VRBaller
VRBallerOP2y ago
Haha it's fine I appreciate you helping!
Brody
Brody2y ago
can you send a post request to that endpoint (while running on railway) with something like postman?
VRBaller
VRBallerOP2y ago
Here's the error that Stripe sees
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<title>Server Error</title>
<style media="screen">
html,body,iframe {
margin: 0;
padding: 0;
}
html,body {
height: 100%;
overflow: hidden;
}
iframe {
width: 100%;
height: 100%;
border: 0;
}
</style>
</head>
<body>
<noscript>
<iframe src="//railway.app/error-pages/project-error?status=503"></iframe>
</noscript>
<script>
(function() {
const iframe = document.createElement("iframe");
const domain = window.location.host.match(/\.up\.railway(-[a-z]+)?\.app$/)
? window.location.host.split(".").slice(-2).join('.')
: "railway.app";
iframe.src = "//"+domain+"/error-pages/project-error?domain="+encodeURIComponent(window.location.host)+"&status=503";
document.body.append(iframe);
})();
(function() {
setInterval(function() {
var xhr = new XMLHttpRequest();
xhr.open('GET', window.location.href);
xhr.onreadystatechange = function () {
if (this.readyState == this.HEADERS_RECEIVED) {
var isFallback = xhr.getResponseHeader("X-Railway-Fallback")
if (isFallback !== "true") {
window.location.reload();
}
}
}
xhr.send();
}, 3000);
})();
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<title>Server Error</title>
<style media="screen">
html,body,iframe {
margin: 0;
padding: 0;
}
html,body {
height: 100%;
overflow: hidden;
}
iframe {
width: 100%;
height: 100%;
border: 0;
}
</style>
</head>
<body>
<noscript>
<iframe src="//railway.app/error-pages/project-error?status=503"></iframe>
</noscript>
<script>
(function() {
const iframe = document.createElement("iframe");
const domain = window.location.host.match(/\.up\.railway(-[a-z]+)?\.app$/)
? window.location.host.split(".").slice(-2).join('.')
: "railway.app";
iframe.src = "//"+domain+"/error-pages/project-error?domain="+encodeURIComponent(window.location.host)+"&status=503";
document.body.append(iframe);
})();
(function() {
setInterval(function() {
var xhr = new XMLHttpRequest();
xhr.open('GET', window.location.href);
xhr.onreadystatechange = function () {
if (this.readyState == this.HEADERS_RECEIVED) {
var isFallback = xhr.getResponseHeader("X-Railway-Fallback")
if (isFallback !== "true") {
window.location.reload();
}
}
}
xhr.send();
}, 3000);
})();
</script>
</body>
</html>
it's railway responding rather than my app. Which is quite odd
Brody
Brody2y ago
that is helpful ?
VRBaller
VRBallerOP2y ago
Can I dm you it?
Brody
Brody2y ago
why (thanks for asking before hand though) lmao scratch that im not gonna reply to the dm #🛂|readme #5
VRBaller
VRBallerOP2y ago
It's private information.
Brody
Brody2y ago
send it here and i will delete it after i copy it, no one here is out to get you
VRBaller
VRBallerOP2y ago
okay
Brody
Brody2y ago
youve wasted a lot of time btw
VRBaller
VRBallerOP2y ago
Why?
VRBaller
VRBallerOP2y ago
Okay Ill take a look at the link Thanks that fixed it
Brody
Brody2y ago
see what i mean?
VRBaller
VRBallerOP2y ago
You're a clown
Brody
Brody2y ago
im glad i could be of assistance (i didnt mean my time btw)
VRBaller
VRBallerOP2y ago
It wasn't a waste of my time .... 🤦
Brody
Brody2y ago
okay 🙂 either way, glad you got it fixed
Want results from more Discord servers?
Add your server