Skip to content

Commit

Permalink
feat: #118 cors default origin
Browse files Browse the repository at this point in the history
  • Loading branch information
Baroshem committed Mar 6, 2023
1 parent 7f0e17c commit d671f56
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -37,6 +37,7 @@
"prepack": "nuxt-module-build",
"dev": "nuxt-module-build --stub && nuxi prepare playground && nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:start": "nuxi start playground",
"dev:generate": "nuxi generate playground",
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
"lint": "eslint --ext .js,.ts,.vue",
Expand Down
6 changes: 3 additions & 3 deletions src/defaultConfig.ts
Expand Up @@ -6,7 +6,7 @@ const defaultGlobalRoute = { route: DEFAULT_GLOBAL_ROUTE }
const defaultMiddlewareRoute = { route: DEFAULT_MIDDLEWARE_ROUTE }
const defaultThrowErrorValue = { throwError: true }

export const defaultSecurityConfig: ModuleOptions = {
export const defaultSecurityConfig = (serverlUrl: string): ModuleOptions => ({
headers: {
crossOriginResourcePolicy: {
value: 'same-origin',
Expand Down Expand Up @@ -101,7 +101,7 @@ export const defaultSecurityConfig: ModuleOptions = {
corsHandler: {
// Options by CORS middleware for Express https://github.com/expressjs/cors#configuration-options
value: {
origin: '*',
origin: serverlUrl as any,
methods: ['GET', 'HEAD', 'PUT', 'PATCH', 'POST', 'DELETE'],
preflight: {
statusCode: 204
Expand All @@ -119,4 +119,4 @@ export const defaultSecurityConfig: ModuleOptions = {
basicAuth: false,
enabled: true,
csrf: false,
}
})
2 changes: 1 addition & 1 deletion src/module.ts
Expand Up @@ -40,7 +40,7 @@ export default defineNuxtModule<ModuleOptions>({
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
nuxt.options.build.transpile.push(runtimeDir)
nuxt.options.security = defuReplaceArray({ ...options, ...nuxt.options.security }, {
...defaultSecurityConfig
...defaultSecurityConfig(nuxt.options.devServer.url)
})
const securityOptions = nuxt.options.security
// Disabled module when `enabled` is set to `false`
Expand Down

0 comments on commit d671f56

Please sign in to comment.