Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set proper headers in UI projects for SnarkyJS #267

Closed
2 of 4 tasks
jasongitmail opened this issue Oct 10, 2022 · 0 comments · Fixed by #279
Closed
2 of 4 tasks

Set proper headers in UI projects for SnarkyJS #267

jasongitmail opened this issue Oct 10, 2022 · 0 comments · Fixed by #279

Comments

@jasongitmail
Copy link
Contributor

jasongitmail commented Oct 10, 2022

The ideal solution is to set headers via middleware, rather than altering a dev server config, so that we can solve it for developers both for development via npm run dev and for production, since that would work with any host they decide to use.

  • SvelteKit. Confirm using curl -I http://localhost:5173. Headers won't show in browser dev tools when npm run dev is run, for some reason. Or can do npm run build && npm run preview and they will appear in browser dev tools.
// src/hooks.server.js
/** @type {import('@sveltejs/kit').Handle} */
export async function handle({ event, resolve }) {
  const response = await resolve(event);
  response.headers.set('Cross-Origin-Opener-Policy', 'same-origin');
  response.headers.set('Cross-Origin-Embedder-Policy', 'require-corp');
  return response;
}
// example, untested
module.exports = {
  async headers() {
    return [
      {
        source: '/*',
        headers: [
          {
            key: 'Cross-Origin-Opener-Policy',
            value: 'same-origin',
          },
          {
            key: 'Cross-Origin-Embedder-Policy',
            value: 'require-corp',
          },
        ],
      },
    ]
  },
}
  • NuxtJS

  • Note in ui READMEs

@jasongitmail jasongitmail changed the title Set proper headers when npm run dev is run Set proper headers in UI projects for SnarkyJS Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant