-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #345 from na2na-p/topic/spotify-callback-endpoint
SpotifyのOAuthコールバック用バックエンドの作成
- Loading branch information
Showing
13 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.DS_Store | ||
|
||
### Terraform template | ||
# Local .terraform directories | ||
**/.terraform/* | ||
|
||
# .tfstate files | ||
*.tfstate | ||
*.tfstate.* | ||
|
||
# Crash log files | ||
crash.log | ||
crash.*.log | ||
|
||
# Exclude all .tfvars files, which are likely to contain sensitive data, such as | ||
# password, private keys, and other secrets. These should not be part of version | ||
# control as they are data points which are potentially sensitive and subject | ||
# to change depending on the environment. | ||
*.tfvars | ||
*.tfvars.json | ||
|
||
# Ignore override files as they are usually used to override resources locally and so | ||
# are not checked in | ||
override.tf | ||
override.tf.json | ||
*_override.tf | ||
*_override.tf.json | ||
|
||
# Include override files you do wish to add to version control using negated pattern | ||
# !example_override.tf | ||
|
||
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan | ||
# example: *tfplan* | ||
|
||
# Ignore CLI configuration files | ||
.terraformrc | ||
terraform.rc |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
locals { | ||
service = "jetdisc" | ||
env = "main" | ||
} | ||
|
||
module "app" { | ||
providers = { | ||
cloudflare = cloudflare | ||
} | ||
|
||
source = "../../modules/app" | ||
service = local.service | ||
env = local.env | ||
account_id = var.account_id | ||
zone_id = var.zone_id | ||
base_domain = var.base_domain | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
provider "cloudflare" { | ||
api_token = var.cloudflare_api_token | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
variable "cloudflare_api_token" { | ||
description = "Cloudflare APIトークン" | ||
type = string | ||
} | ||
|
||
variable "account_id" { | ||
description = "Cloudflare Account ID" | ||
type = string | ||
} | ||
|
||
variable "zone_id" { | ||
description = "Cloudflare Zone ID" | ||
type = string | ||
} | ||
|
||
variable "base_domain" { | ||
description = "Base domain" | ||
type = string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
terraform { | ||
required_version = "1.6.6" | ||
|
||
required_providers { | ||
cloudflare = { | ||
source = "cloudflare/cloudflare" | ||
version = "~> 4.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module "worker" { | ||
source = "./modules/workers" | ||
worker_script_path = "./scripts/worker.js" | ||
account_id = var.account_id | ||
worker_name = "${var.service}-${var.env}" | ||
zone_id = var.zone_id | ||
base_domain = var.base_domain | ||
} |
23 changes: 23 additions & 0 deletions
23
infra/terraform/cloudflare/modules/app/modules/workers/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
locals { | ||
worker_script_dir = "${path.module}/scripts" | ||
} | ||
|
||
resource "cloudflare_worker_script" "worker" { | ||
account_id = var.account_id | ||
name = var.worker_name | ||
content = file("${local.worker_script_dir}/worker.js") | ||
} | ||
|
||
resource "cloudflare_worker_route" "name" { | ||
pattern = "${var.worker_name}.${var.base_domain}" | ||
zone_id = var.zone_id | ||
script_name = cloudflare_worker_script.worker.name | ||
} | ||
|
||
resource "cloudflare_worker_domain" "custom_domain" { | ||
hostname = "${var.worker_name}.${var.base_domain}" | ||
account_id = var.account_id | ||
service = var.worker_name | ||
zone_id = var.zone_id | ||
depends_on = [cloudflare_worker_script.worker] | ||
} |
41 changes: 41 additions & 0 deletions
41
infra/terraform/cloudflare/modules/app/modules/workers/scripts/worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// @ts-check | ||
|
||
addEventListener('fetch', event => { | ||
event.respondWith(handleRequest(event.request)); | ||
}); | ||
|
||
async function handleRequest(request) { | ||
const url = new URL(request.url); | ||
const code = url.searchParams.get('code'); | ||
|
||
if (!code) { | ||
return new Response('No code found in URL.', { status: 400 }); | ||
} | ||
|
||
// HTMLレスポンスを生成 | ||
const htmlContent = ` | ||
<html> | ||
<head> | ||
<title>Spotify Auth Code</title> | ||
</head> | ||
<body> | ||
<h1>Your Spotify Authentication Code</h1> | ||
<p>Copy and paste this code back into your Discord chat:</p> | ||
<div> | ||
<code>${code}</code> | ||
</div> | ||
<button onclick="copyToClipboard()">Copy to Clipboard</button> | ||
</body> | ||
<script> | ||
function copyToClipboard() { | ||
const code = document.querySelector("code"); | ||
navigator.clipboard.writeText(code.textContent); | ||
} | ||
</script> | ||
</html> | ||
`; | ||
|
||
return new Response(htmlContent, { | ||
headers: { 'Content-Type': 'text/html' }, | ||
}); | ||
} |
24 changes: 24 additions & 0 deletions
24
infra/terraform/cloudflare/modules/app/modules/workers/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
variable "worker_name" { | ||
description = "Name of Cloudflare Worker" | ||
} | ||
|
||
variable "worker_script_path" { | ||
description = "Path to Cloudflare Worker script" | ||
type = string | ||
default = "./scripts/worker.js" | ||
} | ||
|
||
variable "account_id" { | ||
description = "Cloudflare Account ID" | ||
type = string | ||
} | ||
|
||
variable "zone_id" { | ||
description = "Cloudflare Zone ID" | ||
type = string | ||
} | ||
|
||
variable "base_domain" { | ||
description = "Base domain" | ||
type = string | ||
} |
10 changes: 10 additions & 0 deletions
10
infra/terraform/cloudflare/modules/app/modules/workers/versions.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
terraform { | ||
required_version = "1.6.6" | ||
|
||
required_providers { | ||
cloudflare = { | ||
source = "cloudflare/cloudflare" | ||
version = "~> 4.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
variable "service" { | ||
type = string | ||
description = "used for resource name and tag prefix" | ||
} | ||
|
||
variable "env" { | ||
type = string | ||
description = "used for resource name and tag prefix" | ||
} | ||
|
||
variable "account_id" { | ||
description = "Cloudflare Account ID" | ||
type = string | ||
} | ||
|
||
variable "zone_id" { | ||
description = "Cloudflare Zone ID" | ||
type = string | ||
} | ||
|
||
variable "base_domain" { | ||
description = "Base domain" | ||
type = string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
terraform { | ||
required_version = "1.6.6" | ||
|
||
required_providers { | ||
cloudflare = { | ||
source = "cloudflare/cloudflare" | ||
version = "~> 4.0" | ||
} | ||
} | ||
} |