Skip to content

webhookUrl() doesn't account for route prefixes #270

@FredrikAnkarang

Description

@FredrikAnkarang

Description

When Webhooks::routes() is registered in a route file with automatic prefixing (e.g., routes/api.php), the generated webhook URLs don't include the prefix, causing 404
errors.

Expected vs Actual

Routes registered at:
api/webhooks/signal/{slug}/{workflowId}/{signal}

URLs generated:
webhooks/signal/{slug}/{workflowId}/{signal}

The api/ prefix is missing from generated URLs.

Root Cause

Laravel automatically prefixes routes in routes/api.php with api/, but Activity::webhookUrl() only uses the webhooks_route config value, unaware of any route prefixes.

Attempted Workaround Fails

Setting config to 'webhooks_route' => 'api/webhooks' causes double prefixing:
api/api/webhooks/signal/...

Proposed Fix

Use Laravel's named routes and route() helper instead of manual URL construction.

Webhooks.php - Add route names:

Route::post(
    "{$basePath}/signal/{$slug}/{workflowId}/{$signal}",
    static function (Request $request, $workflowId) use ($workflow, $method) {
        // ... handler
    }
)->name("workflows.signal.{$slug}.{$signal}");

Activity.php - Use route() helper:

  public function webhookUrl(string $signalMethod = ''): string
  {
      $workflow = Str::kebab(class_basename($this->storedWorkflow->class));

      if ($signalMethod === '') {
          return route("workflows.start.{$workflow}");
      }

      $signal = Str::kebab($signalMethod);
      return route("workflows.signal.{$workflow}.{$signal}", [
          'workflowId' => $this->storedWorkflow->id
      ]);
  }

Benefits:

  • Laravel's route() automatically handles all prefixes, domains, HTTPS, etc.
  • Standard Laravel convention
  • Works with route caching
  • No manual URL construction or prefix configuration needed

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions