Routes
Up to: Mastodon/Docs
Routes are the things that define how URLs get mapped to program logic, and masto defines them in a bunch of places.
Oddly this is one of the few things that mastodon has developer documentation for: https://docs.joinmastodon.org/dev/routes/
Rails
Controllers
These are the "primary" routes - when you make a request to the server, rails is the first thing that catches your request.
- Web interface routes:
config/routes.rb
- API routes:
config/routes/api.rb
(and other routes in there too)
See the Rails routing docs for more on how they work.
The basic pattern for a route will look something like this:
get '/@:account_username/:id', to: 'statuses#show', as: :short_account_status, constraints: { id: /\d.+/ }
When you go to https://neuromatch.social/@account/status_id
, Rails passes the two parameters :account_username
and :id
to the StatusesController
in controllers/statuses_controller.rb
, specifically its show
method.
Views
Rails then implicitly passes those parameters on to a "view," or an html template that is compiled and then returned to the browser. In this case the relationship to the view is also implicit, depending on file names, so the view that is invoked is views/statuses/show.html.haml
.
That page is mostly a stub, because most of the actual rendering of the page is done clientside with react/redux.
React
The react routes are in:
- Main routes
app/javascript/flavours/glitch/features/ui/index.jsx
The React routes map a given URL location to the page that is to be displayed. So while the rails routers will give a little bit of header information to the page, the rest of the page that is served is identical across most pages. The clientside React controls what is shown for a given page, rather than the serverside Rails.
So, for example, the statuses route looks like this:
<WrappedRoute path='/@:acct/:statusId' exact component={Status} content={children} />
Which displays the Status
component (javascript/flavours/glitch/features/status/index.jsx
), passing :acct
and statusId
to the Component's props
.
After that, the guide picks up at Redux