Add endpoints for getting webpush public key and subscribing
This commit is contained in:
parent
32ab9267ec
commit
bae227be76
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Ajax::WebPushController < AjaxController
|
||||
def key
|
||||
certificate = Rpush::Webpush::App.find_by(name: "webpush").certificate
|
||||
|
||||
@response[:key] = JSON.parse(certificate)["public_key"]
|
||||
end
|
||||
|
||||
def subscribe
|
||||
WebPushSubscription.create!(
|
||||
user: current_user,
|
||||
subscription: params[:subscription]
|
||||
)
|
||||
|
||||
@response[:status] = :okay
|
||||
@response[:success] = true
|
||||
end
|
||||
end
|
|
@ -132,6 +132,8 @@ Rails.application.routes.draw do
|
|||
post "/list_membership", to: "list#membership", as: :list_membership
|
||||
post "/subscribe", to: "subscription#subscribe", as: :subscribe_answer
|
||||
post "/unsubscribe", to: "subscription#unsubscribe", as: :unsubscribe_answer
|
||||
get "/webpush/key", to: "web_push#key", as: :webpush_key
|
||||
post "/webpush", to: "web_push#subscribe", as: :webpush_subscribe
|
||||
end
|
||||
|
||||
resource :anonymous_block, controller: :anonymous_block, only: %i[create destroy]
|
||||
|
|
Loading…
Reference in New Issue