File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,3 +6,7 @@ MONGO_URI=mongodb://localhost:27017/
66
77# API の公開 URL(サーバーコンポーネントからの内部アクセス用)
88NEXT_PUBLIC_API_URL = http://localhost:3000/carshare-viewer
9+
10+ # Server Actions で許可する Origin(カンマ区切り,必要時のみ設定)
11+ # 例: SERVER_ACTIONS_ALLOWED_ORIGINS=ktak.dev,www.ktak.dev
12+ SERVER_ACTIONS_ALLOWED_ORIGINS =
Original file line number Diff line number Diff line change @@ -170,6 +170,7 @@ cp .env.sample .env
170170| ` PORT ` | ホストに公開するポート番号(Docker 開発環境のみ) | ` 3200 ` |
171171| ` MONGO_URI ` | MongoDB 接続 URI(形式: ` mongodb://host:port/ ` ) | ` mongodb://db:27017/ ` |
172172| ` NEXT_PUBLIC_API_URL ` | Server Components からの API アクセス URL(通常は変更不要) | ` http://localhost:3000/carshare-viewer ` |
173+ | ` SERVER_ACTIONS_ALLOWED_ORIGINS ` | Server Actions で許可する Origin(カンマ区切り) | - |
173174| ` DOCKER_IMAGE ` | 本番用 Docker イメージ名(` docker-compose.prod.yml ` で使用) | - |
174175
175176### Docker を使用した開発
@@ -326,6 +327,7 @@ cd /path/to/deploy
326327PORT=3200
327328MONGO_URI=mongodb://db:27017/
328329NEXT_PUBLIC_API_URL=https://yourdomain.com/carshare-viewer
330+ SERVER_ACTIONS_ALLOWED_ORIGINS=yourdomain.com,www.yourdomain.com
329331DOCKER_IMAGE=ghcr.io/<owner>/<repo>:latest
330332```
331333
@@ -344,6 +346,12 @@ DOCKER_IMAGE=ghcr.io/<owner>/<repo>:latest
3443462 . タイムズカー API 接続を確認: ` curl https://api.timescar.jp/... `
3453473 . cron 実行ログを確認: ` docker compose -f docker-compose.prod.yml logs app `
346348
349+ ** ` Invalid Server Actions request ` が発生する場合** :
350+
351+ 1 . ` .env ` の ` NEXT_PUBLIC_API_URL ` が実際の公開ドメインと一致しているか確認
352+ 2 . ` SERVER_ACTIONS_ALLOWED_ORIGINS ` に公開ドメインを設定(例: ` ktak.dev,www.ktak.dev ` )
353+ 3 . 再起動: ` docker compose -f docker-compose.prod.yml up -d --force-recreate `
354+
347355## 開発ガイド
348356
349357### ページ構成
Original file line number Diff line number Diff line change 11import type { NextConfig } from 'next' ;
22
3+ const normalizeOriginHost = ( value : string ) : string =>
4+ value . replace ( / ^ h t t p s ? : \/ \/ / , '' ) . replace ( / \/ $ / , '' ) . trim ( ) ;
5+
6+ const getApiUrlHost = ( ) : string => {
7+ const apiUrl = process . env . NEXT_PUBLIC_API_URL ;
8+ if ( ! apiUrl ) return '' ;
9+
10+ try {
11+ return new URL ( apiUrl ) . host ;
12+ } catch {
13+ return normalizeOriginHost ( apiUrl ) ;
14+ }
15+ } ;
16+
17+ const allowedOrigins = Array . from (
18+ new Set (
19+ [
20+ 'localhost:3200' ,
21+ '127.0.0.1:3200' ,
22+ getApiUrlHost ( ) ,
23+ ...( process . env . SERVER_ACTIONS_ALLOWED_ORIGINS ?? '' )
24+ . split ( ',' )
25+ . map ( ( origin ) => normalizeOriginHost ( origin ) )
26+ . filter ( Boolean ) ,
27+ ] . filter ( Boolean ) ,
28+ ) ,
29+ ) ;
30+
331const nextConfig : NextConfig = {
432 basePath : '/carshare-viewer' ,
533 output : 'standalone' ,
34+ experimental : {
35+ serverActions : {
36+ allowedOrigins,
37+ } ,
38+ } ,
639 images : {
740 remotePatterns : [
841 {
You can’t perform that action at this time.
0 commit comments