Skip to content

Commit

Permalink
fix(deps): upgrade @nuxtjs/robots to v3
Browse files Browse the repository at this point in the history
  • Loading branch information
dargmuesli committed Oct 7, 2022
1 parent d1fac59 commit 44ffe30
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion nuxt/composables/useHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const useHost = () => {
if (process.server) {
const event = useRequestEvent()

return getHost(event)
return getHost(event.req)
} else {
return location.host
}
Expand Down
9 changes: 1 addition & 8 deletions nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,7 @@ export default defineNuxtConfig({
// analyticsUacct: process.env.GOOGLE_ANALYTICS_ID,
// },
// ],
[
'@nuxtjs/robots',
{
Allow: ['/'],
Disallow: ['/robots.txt'], // https://webmasters.stackexchange.com/a/117537/70856
Sitemap: BASE_URL + '/sitemap.xml',
},
],
'@nuxtjs/robots',
'@pinia/nuxt',
// ['@nuxtjs/sitemap', { exclude: SITEMAP_EXCLUSIONS_LOCALIZED, i18n: true }], // Should be declared at the end of the array.
],
Expand Down
2 changes: 1 addition & 1 deletion nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@http-util/status-i18n": "0.6.2",
"@nuxtjs/color-mode": "3.1.7",
"@nuxtjs/i18n": "npm:@nuxtjs/i18n-edge@^8.0.0-alpha.2-27747905.3a73d90",
"@nuxtjs/robots": "2.5.0",
"@nuxtjs/robots": "3.0.0-1",
"@nuxtjs/sitemap": "2.4.0",
"@pinia/nuxt": "0.4.2",
"@tailwindcss/forms": "0.5.3",
Expand Down
8 changes: 4 additions & 4 deletions nuxt/plugins/util/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CombinedError } from '@urql/core'
import Clipboard from 'clipboard'
import { CompatibilityEvent } from 'h3'
import { IncomingMessage } from 'h3'
import { computed, Ref } from 'vue'

export function append(path: string, pathToAppend: string): string {
Expand Down Expand Up @@ -55,10 +55,10 @@ export function copyText(text: string) {
// return promise
// }

export function getHost(event: CompatibilityEvent) {
if (!event.req.headers.host) throw new Error('Host header is not given!')
export function getHost(req: IncomingMessage) {
if (!req.headers.host) throw new Error('Host header is not given!')

return event.req.headers.host
return req.headers.host
}

export function getApiDataDefault() {
Expand Down
12 changes: 8 additions & 4 deletions nuxt/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions nuxt/robots.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { IncomingMessage } from 'h3'

import { getHost } from './plugins/util/util'

export default {
allow: ['/'],
disallow: [
'/robots.txt', // https://webmasters.stackexchange.com/a/117537/70856
],
sitemap: (req: IncomingMessage) => {
return `https://${getHost(req)}/sitemap.xml`
},
}
2 changes: 1 addition & 1 deletion nuxt/server/middleware/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function getCspAsString(host: string): string {
}

export default defineEventHandler((event) => {
const host = getHost(event)
const host = getHost(event.req)

appendHeader(event, 'Content-Security-Policy', getCspAsString(host))
// appendHeader(event, 'Cross-Origin-Embedder-Policy', 'require-corp') // https://stackoverflow.com/questions/71904052/getting-notsameoriginafterdefaultedtosameoriginbycoep-error-with-helmet
Expand Down

0 comments on commit 44ffe30

Please sign in to comment.