import Cookie from 'js-cookie'

export default {
  // 获取服务端cookie
  getcookiesInServer: function (req) {
    console.log('get server cookie')
    const service_cookie = {}
    req &&
      req.headers.cookie &&
      req.headers.cookie.split(';').forEach(function (val) {
        const parts = val.split('=')
        service_cookie[parts[0].trim()] = (parts[1] || '').trim()
      })
    return service_cookie
  },
  // 获取客户端cookie
  getcookiesInClient: function (key) {
    if (Cookie.get('can-use-cookie')) {
      return Cookie.get(key) || ''
    } else {
      return ''
    }
  },
}
