diff --git a/.env.example b/.env.example index f00f78b..b50f576 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,6 @@ API_KEY="SOME_APIKEY" SERVICE_DOMAIN=SERVCIE_DOMAIN -NEXT_PUBLIC_SITE_URL=https://funtech.inc/ \ No newline at end of file +NEXT_PUBLIC_SITE_URL=https://funtech.inc/ +# Basic認証 (以下を追加するとBasic認証が有効になります) +# BASIC_AUTH_USERNAME=username +# BASIC_AUTH_PASSWORD=password \ No newline at end of file diff --git a/app/[lang]/_layout/Inner/inner.module.scss b/app/[lang]/_layout/Inner/inner.module.scss index 0f1a451..d78b84c 100644 --- a/app/[lang]/_layout/Inner/inner.module.scss +++ b/app/[lang]/_layout/Inner/inner.module.scss @@ -8,10 +8,10 @@ width: min(100% - $inner-padding, $inner-outer); } .w_wide { - width: min(100% - $inner-padding, $inner-middle); + width: min(100% - $inner-padding, $inner-wide); } .w_default { - width: min(100% - $inner-padding, $inner-wide); + width: min(100% - $inner-padding, $inner-default); } .w_narrow { width: min(100% - $inner-padding, $inner-narrow); diff --git a/middleware.ts b/middleware.ts index 109e925..b3ac5d0 100644 --- a/middleware.ts +++ b/middleware.ts @@ -27,6 +27,33 @@ function getLocale(request: NextRequest): string | undefined { const PUBLIC_FILE = /\.(.*)$/; export function middleware(request: NextRequest) { + + // Basic Auth + if (process.env.NODE_ENV !== "development" && process.env.BASIC_AUTH_USERNAME && process.env.BASIC_AUTH_PASSWORD) { + const basicAuth = request.headers.get("authorization"); + + if (!basicAuth) { + return new Response("Authentication required", { + status: 401, + headers: { + "WWW-Authenticate": 'Basic realm="Secure Area"', + }, + }); + } + + try { + const authValue = basicAuth.split(" ")[1]; + const [user, pwd] = atob(authValue).split(":"); + + if (user !== process.env.BASIC_AUTH_USERNAME || pwd !== process.env.BASIC_AUTH_PASSWORD) { + return new Response("Unauthorized", { status: 401 }); + } + } catch (e) { + return new Response("Invalid Authentication", { status: 400 }); + } + } + + const pathname = request.nextUrl.pathname; // skips adding the public files