R
Railway16mo ago
VRBaller

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
Percy16mo ago
Project ID: N/A
Percy
Percy16mo ago
You can use the railway provided variable RAILWAY_STATIC_URL in code to register your webhook endpoint.
⚠️ experimental feature
Brody
Brody16mo ago
where do you register this webhook?
VRBaller
VRBaller16mo ago
It's an endpoint in our app. /payments/webhook
Brody
Brody16mo ago
yes but where do you tell stripe to call that endpoint?
VRBaller
VRBaller16mo ago
Ah, Stripe has https://dashboard.stripe.com/test/webhooks. It's registered there
Brody
Brody16mo ago
screenshot please
VRBaller
VRBaller16mo ago
Brody
Brody16mo ago
okay looks fine now show me the bit of code that handles that endpoint
VRBaller
VRBaller16mo 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
Brody16mo ago
what language is that
VRBaller
VRBaller16mo ago
Typescript
Brody
Brody16mo ago
looks gross
VRBaller
VRBaller16mo ago
... That makes you look bad ngl Actually works quite well look up nest.js
Brody
Brody16mo ago
im not saying your code is gross anyway
VRBaller
VRBaller16mo ago
Haha it's fine I appreciate you helping!
Brody
Brody16mo ago
can you send a post request to that endpoint (while running on railway) with something like postman?
VRBaller
VRBaller16mo 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
Brody16mo ago
that is helpful ?
VRBaller
VRBaller16mo ago
Can I dm you it?
Brody
Brody16mo ago
why (thanks for asking before hand though) lmao scratch that im not gonna reply to the dm #🛂|readme #5
VRBaller
VRBaller16mo ago
It's private information.
Brody
Brody16mo ago
send it here and i will delete it after i copy it, no one here is out to get you
VRBaller
VRBaller16mo ago
okay
Brody
Brody16mo ago
youve wasted a lot of time btw
VRBaller
VRBaller16mo ago
Why?
VRBaller
VRBaller16mo ago
Okay Ill take a look at the link Thanks that fixed it
Brody
Brody16mo ago
see what i mean?
VRBaller
VRBaller16mo ago
You're a clown
Brody
Brody16mo ago
im glad i could be of assistance (i didnt mean my time btw)
VRBaller
VRBaller16mo ago
It wasn't a waste of my time .... 🤦
Brody
Brody16mo ago
okay 🙂 either way, glad you got it fixed
Want results from more Discord servers?
Add your server
More Posts
CSS blocked:mixed-content for gunicorn server | HTTPS | FastAPI | Serving HTMLproject id: `22ce14b2-4953-42e3-aed4-b106fa5da66e/service/c5ee3e3a-1864-440a-bd31-c67e7acf0494?id=e9Spring Eureka & Cloud Gateway and microservice resolutionI have deployed a three-service project which contains: - Eureka Server - Spring Cloud gateway (api RpcIpcMessagePortClosedError: Process 38 exited [SIGKILL].Hi, I'm deploying a ReactJS app, the build succeeds, it gets containerized and on deployment I get tUnable to write in public file in laravelHello, i'm getting an error Unable to write in the \"/app/public/assets/img when tryng to upload filautomatically restarting my springboot application every 24 hours at 00:00 GMTHello, I have a web-based puzzle game that retrieves words from the database, every 24 hours. I madeYarn build is not optimizedI've defined `yarn build` as my Build Command for a React website, however in the deploy logs I get:Usage and Bills without any active deployI have one project created (Spring Boot Eureka). I have deployed it succesfully, but now 0 deploymenClient without GitHub on RailwayHi, I have a problem with pricing. I have a client who wants an app with a database, and I've decidecustom domain not workingcould anyone help me with setting up a custom domain? Check the image below, I added the cname recorRollback causes ${{Redis.REDIS_URL}} variables to be missing from configLove the rollback feature, its a lifesaver. although it seems to rollback my instance to a state whe