Michael T
Michael T

Reputation: 826

Rails app with ngrok: Unable to route to POST /api/callbacks/payfast_notifications despite route being defined

I'm encountering an issue with my Rails application where a route I've defined is not being recognized when accessed. Here are the details:

The Setup

I'm using puma-dev to run my Rails development environment. The app runs on the standard HTTP and HTTPS ports, 80 and 443, respectively. I'm using ngrok to expose my development environment to the public internet. This is important because I'm working with an external payment gateway (PayFast) which sends callbacks to my app.

Setup Details:

I am utilizing puma-dev to run my app locally. Ports: HTTP (80), HTTPS (443), and puma-dev's DNS resolution (9253 on localhost). For development testing, I am using:

ngrok http --host-header=api.site_name.test 80

The Issue

When the external service (PayFast) tries to send a callback to /api/callbacks/payfast_notifications, I get the following error:

NGROK: HTTP Requests                                                                                  
POST /api/callbacks/payfast_notifications 404 Not Found

In my Rails logs:

ActionController::RoutingError (No route matches [POST] "/api/callbacks/payfast_notifications"):

Route Definition

The route in question is defined in a module named CallbackRoutes:

module CallbackRoutes
  def self.extended(router)
    router.instance_exec do
      scope '/api/callbacks' do
        scope :module => 'callbacks_api', :as => 'callbacks_api' do
          resources :payfast_notifications, only: [:create]
          # ... [other routes]
        end
      end
    end
  end
end

And in my routes.rb:

Rails.application.routes.draw do
  constraints DomainConstraint.new([REDACTED]) do
    extend CallbackRoutes
    # ... [other routes]
  end
end

When I run rails routes, I can confirm the route is present:

callbacks_api_payfast_notifications POST /api/callbacks/payfast_notifications(.:format) callbacks_api/payfast_notifications#create

What I've tried:

Despite these attempts, the issue persists.

Upvotes: 0

Views: 241

Answers (0)

Related Questions