Configuring Spree as backend only: mounting only the admin and API routes

1,539 views
Skip to first unread message

Tiago Motta Jorge

unread,
Feb 15, 2013, 12:14:25 PM2/15/13
to spree...@googlegroups.com
Hi!

   I'm building a store using Spree only as a backend, through its API. The thing is: I would like to be able to access only the admin and API routes, and none of its other routes. One way to accomplish this is to remove all other routes from all its gems, but this would impose a big overhead every time I wish to upgrade my Spree.

   Does anyone know an easier way to mount only the admin and API routes?


Regards!
Tiago.

Nate Lowrie

unread,
Feb 15, 2013, 2:35:51 PM2/15/13
to spree...@googlegroups.com
Tiago,

There has already been work done to split the next version of spree into frontend and backend modules so you can do exactly what your describing.  Not sure when the next release is planned, but it will definitely be in the next release as far as I can tell.

Regards,

Nate

Tiago Motta Jorge

unread,
Feb 15, 2013, 4:24:15 PM2/15/13
to spree...@googlegroups.com
Yeah, Spree 2 will be great! But I don't know if it will be ready by the time that I need it... so, I'm studying how to do this, anyway. I've found a way by adding these lines to my routes.rb, before the "mount Spree::Core::Engine, :at => '/spree'" line:

  match "/spree/products" => redirect("/spree/admin")
  match "/spree/products/*p" => redirect("/spree/admin")
  
  match "/spree/checkout" => redirect("/spree/admin")
  match "/spree/checkout/*p" => redirect("/spree/admin")
  
  match "/spree/orders/*p" => redirect("/spree/admin")
  
  match "/spree/cart" => redirect("/spree/admin")
  match "/spree/cart/*p" => redirect("/spree/admin")
  
  match "/spree/t/*p" => redirect("/spree/admin")


   It works... What do you think? Makes sense?


Regards!
Tiago.

Ryan Bigg

unread,
Feb 18, 2013, 1:22:59 AM2/18/13
to spree...@googlegroups.com
Yes, the routes seem fine.

You could try using "Spree 2" now and see how far you get. It's relatively easy to just include Core, API and Backend.


--
You received this message because you are subscribed to the Google Groups "Spree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spree-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Tiago Motta Jorge

unread,
Feb 18, 2013, 6:05:31 AM2/18/13
to spree...@googlegroups.com, spree...@googlegroups.com
Hmmm... Sounds interesting! When do you plan to release it? It is in beta yet, isn't it?

[]s,
Tiago.

Brian Quinn

unread,
Feb 18, 2013, 6:27:54 AM2/18/13
to spree...@googlegroups.com
Using master (aka 2.0) won't help with the routes as both the frontend and backend gems append their routes onto Core's.

@Radar - maybe we should let them have their own routes, and remove routes from core? It would make sense, considering core has no controllers anymore? It would break a lot of extensions, but maybe we could keep Spree::Core::Engine.routes.prepend and append  methods around to warn people of the change?


--
Brian Quinn

Co-Founder, CTO
Spree Commerce, Inc.

Tiago Motta Jorge

unread,
Feb 18, 2013, 7:16:41 AM2/18/13
to spree...@googlegroups.com
WOW! This change would be awesome!

But even without this change, is Spree 2.0 ready for prime time?


Regards,
Tiago.

bl...@maytro.com

unread,
Feb 18, 2013, 3:09:54 PM2/18/13
to spree...@googlegroups.com
I'm also in the process of doing the same thing. Thank you for posting up your solution regarding the overriding of the user facing routes.

Blake

Tiago Motta Jorge

unread,
Feb 18, 2013, 3:37:03 PM2/18/13
to spree...@googlegroups.com
Cool! If you happen to find some route that I may have forgotten to
override, please tell me. ;)

Regards!
Tiago.

Ryan Bigg

unread,
Feb 18, 2013, 6:52:22 PM2/18/13
to spree...@googlegroups.com
On Mon, Feb 18, 2013 at 10:27 PM, Brian Quinn <br...@spreecommerce.com> wrote:
Using master (aka 2.0) won't help with the routes as both the frontend and backend gems append their routes onto Core's.

@Radar - maybe we should let them have their own routes, and remove routes from core? It would make sense, considering core has no controllers anymore? It would break a lot of extensions, but maybe we could keep Spree::Core::Engine.routes.prepend and append  methods around to warn people of the change?

Brian:

The prepend+append methods come from Rails itself. I don't think we should ever override these. These routes need to be mounted at a common point so that the routing helper stays as "spree.root_path" and not "spree_frontend.root_path" and "spree_backend.admin_root_path"

Tiago:

You can use just backend and api by putting this in your Gemfile:

gem 'spree_backend', :github => "spree/spree"

This will automatically include core + api because they are both dependencies of backend. You can be explicit about both those dependencies if you wish.

Master branch is the *least* stable of all the branches, so I would definitely not advise using it for anything critical right now. If you would like to build your app against it and test it, that would be very awesome. Thanks!

Brian Quinn

unread,
Feb 19, 2013, 4:47:20 AM2/19/13
to spree...@googlegroups.com
@Radar - that makes perfect sense, so what about having someway to control if the routes get appended/prepended onto Core? Like a preference check or something?


#frontend/config/routes.rb

if Spree::Config.use_frontend
  Spree::Core::Engine.routes.prepend do
    ….
  end
end



--
Brian Quinn

Co-Founder, CTO
Spree Commerce, Inc.

Tiago Motta Jorge

unread,
Feb 19, 2013, 5:17:20 AM2/19/13
to spree...@googlegroups.com, spree...@googlegroups.com
Thank you, Ryan! I'll give it a try!

[]s,
Tiago.

Nate Lowrie

unread,
Feb 20, 2013, 7:55:57 AM2/20/13
to spree...@googlegroups.com
On Tuesday, February 19, 2013 4:47:20 AM UTC-5, Brian Quinn wrote:
@Radar - that makes perfect sense, so what about having someway to control if the routes get appended/prepended onto Core? Like a preference check or something?


#frontend/config/routes.rb

if Spree::Config.use_frontend
  Spree::Core::Engine.routes.prepend do
    ….
  end
end


We already have that now in the master branch without needing a preference. If you don't want the frontend routes prepend, just don't install the spree_frontend gem.

Regards,

Nate

Ryan Bigg

unread,
Feb 20, 2013, 4:30:31 PM2/20/13
to spree...@googlegroups.com
Nate took the words out my fingers ;)

 
--

Brian Quinn

unread,
Feb 21, 2013, 1:59:34 AM2/21/13
to spree...@googlegroups.com
Nate / Ryan - that's a good point.. so ignore my stupid suggestion then.

Ryan - we should include an example of using just the backend + api in the guides maybe?


--
Brian Quinn

Co-Founder, CTO
Spree Commerce, Inc.

Stefan Wrobel

unread,
Feb 22, 2013, 5:07:10 PM2/22/13
to spree...@googlegroups.com
Suuuuuper exciting stuff guys! Is there a list of breaking changes kept anywhere?

Ryan Bigg

unread,
Feb 27, 2013, 9:39:57 AM2/27/13
to spree...@googlegroups.com
Brian: Yes we will include an example of just using pieces of Spree in the new guides.

Stefan: Yes, there will be a list of breaking changes compiled when we're getting closer to the Spree 2 release.

Stefan Wrobel

unread,
Feb 27, 2013, 1:49:35 PM2/27/13
to spree-user
Ok, just my $0.02 but it's probably easier to maintain the list as you go than go in and try to backfill it after all the work is done, but I'm sure you guys have a process :)


--
You received this message because you are subscribed to a topic in the Google Groups "Spree" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/spree-user/EWwz3CmV32s/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to spree-user+...@googlegroups.com.

Tiago Motta Jorge

unread,
May 22, 2013, 6:06:54 PM5/22/13
to spree...@googlegroups.com
Hi, guys!

I've found a better way to disable the frontend of a Spree 1.3.x installation. We can add a filter to the StoreController, creating a file called "app/controllers/spree/store_controller_decorator.rb, with this code:

Spree::StoreController.class_eval do
  before_filter :redirect_to_admin
 
  def redirect_to_admin
    redirect_to admin_url
  end
end



Regards!
Tiago.

Mohammed Gharbi

unread,
Jul 1, 2015, 10:15:56 AM7/1/15
to spree...@googlegroups.com
Tiago, Did you try to do the same with the routes of spree_auth_devise frontend?

Regards,

Tiago Motta Jorge

unread,
Jul 1, 2015, 12:14:13 PM7/1/15
to spree...@googlegroups.com
No, I did not.

Reply all
Reply to author
Forward
0 new messages