s1rc's avatar
Level 1

Route defaulting to localhost after passing through SQS queue to ElasticBeanstalk Worker

I have a primary web/api Laravel app and a worker Laravel app both running on AWS ElasticBeanstalk. The web/api app is public facing, the worker is not. Both apps have a shared common package, in which the notifications, models, etc. are stored.

Sending mail notifications from the web app to SQS, the worker picks them up and sends them correctly. However the routes in the notifications are not returning the domain of the web app, but instead https://localhost/.

I've checked on the worker, the APP_URL is configured properly (php artisan route:list shows them). Even using tinker config('app.url'); returns the correct URL on the worker.

I know the routes are working, because the models passed to the route() are being resolved to their IDs correctly.

0 likes
6 replies
Snapey's avatar

Is the app.url correct on the web frontend? I wonder if the url is being serialised in the job?

s1rc's avatar
Level 1

app.url is the same on the web frontend.

I intercepted the message going through SQS, and the command portion of the message body is quite cryptic, however doesn't seem to make mention of any route. I can see User model passed through the Notification constructor is correct.

Snapey's avatar

In the notification template, how are the links specified?

s1rc's avatar
Level 1

Here's an example of the toMail() function:

return (new MailMessage)
->subject(trans('strings.emails.event.created.subject') . $this->event->group->name)
->markdown('mail.event.created', ['group_name' => $this->event->group->name, 'event_title' => $this->event->title, 'url' => route('frontend.event.show', ['group' => $this->event->group, 'event' => $this->event])]);

When I'm working locally, even through SQS the route generates fine. Tinkering some more, on the worker route('frontend.event.show', ['group' => $this->event->group, 'event' => $this->event]) generates correctly.

s1rc's avatar
Level 1

If I set the route to abosolute = false then append the config('app.url'), it seems to work through SQS.

e.g. 'url' => config('app.url') . route('frontend.event.show', ['group' => $this->event->group, 'event' => $this->event], false)

While it's good that this works, I'm confused why absolute routes won't work through SQS.

Snapey's avatar

My understanding was that the route helper used the hostname from the request and if this was not available (eg when using artisan command) then it falls back to app_url.

But it sounds like this is not the case?

Please or to participate in this conversation.