Skip to content

Commit

Permalink
test: try to simplify reproduction for #411
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 10, 2020
1 parent 1509987 commit c0f1daf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 51 deletions.
6 changes: 2 additions & 4 deletions test/fixture/api/cookie.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export default (req, res) => {
const reqValue = (new URLSearchParams(req.headers.cookie || '').get('mycookie') || '').split(';')[0].trim()
const newValue = Math.round(Math.random() * 1000) + ''
res.setHeader('Set-Cookie', `mycookie=${newValue}; path=/`)
res.end(JSON.stringify([reqValue, newValue], null, 2))
const reqCookie = (new URLSearchParams(req.headers.cookie || '').get('mycookie') || '').split(';')[0].trim()
res.end(reqCookie || '')
}
21 changes: 0 additions & 21 deletions test/fixture/pages/cookie-client.vue

This file was deleted.

26 changes: 0 additions & 26 deletions test/fixture/pages/cookie-server.vue

This file was deleted.

33 changes: 33 additions & 0 deletions test/fixture/pages/cookie.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<template>
<div>
<pre style="display: none">_req:{{ reqCookie }}</pre>
<p>Pass: {{ pass }}</p>
</div>
</template>

<script>
export default {
async asyncData ({ app }) {
const reqCookie = (await app.$axios.$get('/cookie')) + ''
return {
reqCookie
}
},
data () {
return {
pass: '?'
}
},
async mounted () {
const randomValue = Math.round(Math.random() * 1000) + ''
document.cookie = `mycookie=${randomValue}; path=/`
// Render page with server-side, expecting to be rendered with same new cookie
const html = await this.$axios.$get(window.location.href)
const m = html.match(/_req:(\w+)/)
const profifiedSSRCookie = m && m[1]
this.pass = randomValue === profifiedSSRCookie
}
}
</script>

0 comments on commit c0f1daf

Please sign in to comment.