import querystring from 'querystring' import { IForm } from '~/models/submit' const ENDPOINT = "https://json_2series.digitalent.tw/users" const ENDPOINT2 = "https://nodered.digitalent.tw/20201114safe" export default { template: '
OK
', async middleware({ req, error, $axios, redirect }) { const data : IForm = await new Promise((resolve) => { let body = '' req.on('data', data => { body += data }) req.on('end', () => { resolve(JSON.parse(body)) }) }) const uid = data.LINEUserID = data.LINEUserID || 'test' let response = await $axios.get(ENDPOINT, { params: { LINEUserID: uid } }) //data.BeaconMode = 'leave' //data.FLAG = false if (response.data.length > 0) { const id = response.data[0].id await $axios.patch(`${ENDPOINT}/${id}`, data) } else { await $axios.post(ENDPOINT, data) } await $axios.get(ENDPOINT2, { params: { userid: uid } }) } }