IOS通知软件Bark服务端 部署

33 min read

Bark服务端 IOS 部署

使用traefik作为容器网关

version: '3.7'
services:
  bark-server:
    image: finab/bark-server
    container_name: bark-server
    restart: always
    networks:
        - proxy
    volumes:
      - ./data:/data

    labels:
        - "traefik.enable=true"
        - "traefik.http.routers.bark.rule=Host(`bark.a.com`)"
        - "traefik.http.routers.bark.entrypoints=websecure"
        - "traefik.http.routers.bark.service=bark-service"
        - "traefik.http.services.bark-service.loadBalancer.server.port=8080"

networks:
  proxy:
    external: true

测试: https://bark.a.com/ping

正常则返回

{
code: 200,
message: "pong",
timestamp: 1637814712
}

手机端配置

在IOS手机端填写域名 bark.a.com , 手机端的首页将会生成认证的token

浏览器端配置

插件地址: https://chrome.google.com/webstore/detail/bark/pmlkbdbpglkgbgopghdcmohdcmladeii/related

右键插件图标,options选项填写首页生成的请求地址

发送请求

同时支持 get post两种方式

package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"bytes"
)

func sendPush() {
	// push (POST http://127.0.0.1:8080/push)

	json := []byte(`{"body": "Test Bark Server","device_key": "nysrshcqielvoxsa","title": "bleem","ext_params": {"badge": 1, "icon": "https://day.app/assets/images/avatar.jpg", "group": "test", "url": "https://mritd.com"},"category": "category","sound": "minuet.caf"}`)
	body := bytes.NewBuffer(json)

	// Create client
	client := &http.Client{}

	// Create request
	req, err := http.NewRequest("POST", "http://127.0.0.1:8080/push", body)
	if err != nil {
		fmt.Println("Failure : ", err)
	}

	// Headers
	req.Header.Add("Content-Type", "application/json; charset=utf-8")

	// Fetch Request
	resp, err := client.Do(req)
	
	if err != nil {
		fmt.Println("Failure : ", err)
	}

	// Read Response Body
	respBody, _ := ioutil.ReadAll(resp.Body)

	// Display Results
	fmt.Println("response Status : ", resp.Status)
	fmt.Println("response Headers : ", resp.Header)
	fmt.Println("response Body : ", string(respBody))
}