Rest API's in Elixir

Hey Everyone!

Hope so you are doing well. I am here with a new query in my mind. I am just want to ask you something about the Elixir Routes in Rest API’s.

There is an Error of CORS Privacy Policy and i resolve it using OPTIONS Routes in Router file like,

pipeline :api do
  plug CORSPlug
  # ...
end

scope "/api", PhoenixApp do
  pipe_through :api

  resources "/articles", ArticleController
  options   "/articles", ArticleController, :options
  options   "/articles/:id", ArticleController, :options
end

But i am not sure about why we are using these one or why we are duplicating our Routes.

Anyone here can help ??

You can use a “catch-all” match to avoid repeating the routes:

options "/*path", ArticleController, :options

@stefanchrobot its working by using these two Routes. I want something that include just one Route.

resources "/articles", ArticleController
options "/*path", ArticleController, :options

I don’t think this is possible with the current version of CORSPlug. I think you’d need to open an issue in the project.

yes this issue have been resolved using Corsica Plug

Thanks everyone for your help.

1 Like