Skip to content

Commit

Permalink
fix: h3 imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Baroshem committed Mar 9, 2023
1 parent 3b2baca commit 1b94de6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { resolve, normalize } from 'pathe'
import { defineNuxtModule, addServerHandler, installModule } from '@nuxt/kit'
import defu, { createDefu } from 'defu'
import { RuntimeConfig } from '@nuxt/schema'
import { H3CorsOptions } from 'h3'
import {
AllowedHTTPMethods,
BasicAuth,
CorsOptions,
MiddlewareConfiguration,
ModuleOptions,
RateLimiter,
Expand Down Expand Up @@ -131,7 +131,7 @@ export default defineNuxtModule<ModuleOptions>({
const corsHandlerConfig = nuxt.options.security.corsHandler
if (corsHandlerConfig) {
addServerHandler({
route: (corsHandlerConfig as MiddlewareConfiguration<H3CorsOptions>)
route: (corsHandlerConfig as MiddlewareConfiguration<CorsOptions>)
.route,
handler: normalize(
resolve(runtimeDir, 'server/middleware/corsHandler')
Expand Down
16 changes: 14 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { H3CorsOptions } from 'h3'
import { ModuleOptions as CsrfOptions } from 'nuxt-csurf'

export type RequestSizeLimiter = {
Expand Down Expand Up @@ -26,6 +25,19 @@ export type BasicAuth = {
message: string;
}

// Cannot use the H3CorsOptions from `h3` as it breaks the build process for some reason :(
export type CorsOptions = {
origin?: "*" | "null" | string | (string | RegExp)[] | ((origin: string) => boolean);
methods?: "*" | HTTPMethod[];
allowHeaders?: "*" | string[];
exposeHeaders?: "*" | string[];
credentials?: boolean;
maxAge?: string | false;
preflight?: {
statusCode?: number;
};
}

export type HTTPMethod = 'GET' | 'POST' | 'DELETE' | 'PATCH' | 'POST' | string;

export type AllowedHTTPMethods = HTTPMethod[] | '*'
Expand Down Expand Up @@ -256,7 +268,7 @@ export interface ModuleOptions {
requestSizeLimiter: MiddlewareConfiguration<RequestSizeLimiter> | false;
rateLimiter: MiddlewareConfiguration<RateLimiter> | false;
xssValidator: MiddlewareConfiguration<XssValidator> | false;
corsHandler: MiddlewareConfiguration<H3CorsOptions> | false;
corsHandler: MiddlewareConfiguration<CorsOptions> | false;
allowedMethodsRestricter: MiddlewareConfiguration<AllowedHTTPMethods> | false;
hidePoweredBy: boolean;
basicAuth: MiddlewareConfiguration<BasicAuth> | boolean;
Expand Down

1 comment on commit 1b94de6

@vercel
Copy link

@vercel vercel bot commented on 1b94de6 Mar 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nuxt-security – ./

nuxt-security-git-main-baroshem.vercel.app
nuxt-security-baroshem.vercel.app
nuxt-security.vercel.app

Please sign in to comment.