create-svelte
Advanced tools
Comparing version 2.0.0-next.65 to 2.0.0-next.66
# create-svelte | ||
## 2.0.0-next.66 | ||
### Patch Changes | ||
- 1753987: Use request.locals | ||
## 2.0.0-next.65 | ||
@@ -4,0 +10,0 @@ |
@@ -8,3 +8,3 @@ [ | ||
"name": "src/hooks.js", | ||
"contents": "import cookie from 'cookie';\nimport { v4 as uuid } from '@lukeed/uuid';\n\nexport const getContext = (request) => {\n\tconst cookies = cookie.parse(request.headers.cookie || '');\n\n\treturn {\n\t\tis_new: !cookies.userid,\n\t\tuserid: cookies.userid || uuid()\n\t};\n};\n\nexport const handle = async ({ request, render }) => {\n\t// TODO https://github.com/sveltejs/kit/issues/1046\n\tconst response = await render({\n\t\t...request,\n\t\tmethod: (request.query.get('_method') || request.method).toUpperCase()\n\t});\n\n\tconst { is_new, userid } = request.context;\n\n\tif (is_new) {\n\t\t// if this is the first time the user has visited this app,\n\t\t// set a cookie so that we recognise them when they return\n\t\treturn {\n\t\t\t...response,\n\t\t\theaders: {\n\t\t\t\t...response.headers,\n\t\t\t\t'set-cookie': `userid=${userid}; Path=/; HttpOnly`\n\t\t\t}\n\t\t};\n\t}\n\n\treturn response;\n};\n" | ||
"contents": "import cookie from 'cookie';\nimport { v4 as uuid } from '@lukeed/uuid';\n\nexport const handle = async ({ request, render }) => {\n\tconst cookies = cookie.parse(request.headers.cookie || '');\n\trequest.locals.userid = cookies.userid || uuid();\n\n\t// TODO https://github.com/sveltejs/kit/issues/1046\n\tif (request.query.has('_method')) {\n\t\trequest.method = request.query.get('_method').toUpperCase();\n\t}\n\n\tconst response = await render(request);\n\n\tif (!cookies.userid) {\n\t\t// if this is the first time the user has visited this app,\n\t\t// set a cookie so that we recognise them when they return\n\t\tresponse.headers[\n\t\t\t'set-cookie'\n\t\t] = `userid=${request.locals.userid}; Path=/; HttpOnly`;\n\t}\n\n\treturn response;\n};\n" | ||
}, | ||
@@ -11,0 +11,0 @@ { |
@@ -8,3 +8,3 @@ [ | ||
"name": "src/hooks.ts", | ||
"contents": "import cookie from 'cookie';\nimport { v4 as uuid } from '@lukeed/uuid';\nimport type { GetContext, Handle } from '@sveltejs/kit';\n\nexport const getContext: GetContext = (request) => {\n\tconst cookies = cookie.parse(request.headers.cookie || '');\n\n\treturn {\n\t\tis_new: !cookies.userid,\n\t\tuserid: cookies.userid || uuid()\n\t};\n};\n\nexport const handle: Handle = async ({ request, render }) => {\n\t// TODO https://github.com/sveltejs/kit/issues/1046\n\tconst response = await render({\n\t\t...request,\n\t\tmethod: (request.query.get('_method') || request.method).toUpperCase()\n\t});\n\n\tconst { is_new, userid } = request.context;\n\n\tif (is_new) {\n\t\t// if this is the first time the user has visited this app,\n\t\t// set a cookie so that we recognise them when they return\n\t\treturn {\n\t\t\t...response,\n\t\t\theaders: {\n\t\t\t\t...response.headers,\n\t\t\t\t'set-cookie': `userid=${userid}; Path=/; HttpOnly`\n\t\t\t}\n\t\t};\n\t}\n\n\treturn response;\n};\n" | ||
"contents": "import cookie from 'cookie';\nimport { v4 as uuid } from '@lukeed/uuid';\nimport type { Handle } from '@sveltejs/kit';\n\nexport const handle: Handle = async ({ request, render }) => {\n\tconst cookies = cookie.parse(request.headers.cookie || '');\n\trequest.locals.userid = cookies.userid || uuid();\n\n\t// TODO https://github.com/sveltejs/kit/issues/1046\n\tif (request.query.has('_method')) {\n\t\trequest.method = request.query.get('_method').toUpperCase();\n\t}\n\n\tconst response = await render(request);\n\n\tif (!cookies.userid) {\n\t\t// if this is the first time the user has visited this app,\n\t\t// set a cookie so that we recognise them when they return\n\t\tresponse.headers['set-cookie'] = `userid=${request.locals.userid}; Path=/; HttpOnly`;\n\t}\n\n\treturn response;\n};\n" | ||
}, | ||
@@ -11,0 +11,0 @@ { |
{ | ||
"name": "create-svelte", | ||
"version": "2.0.0-next.65", | ||
"version": "2.0.0-next.66", | ||
"bin": "./bin.js", | ||
@@ -10,3 +10,3 @@ "dependencies": { | ||
"devDependencies": { | ||
"@sveltejs/kit": "1.0.0-next.98", | ||
"@sveltejs/kit": "1.0.0-next.99", | ||
"@types/gitignore-parser": "^0.0.0", | ||
@@ -13,0 +13,0 @@ "@types/prettier": "^2.2.3", |
545748
766