Skip to content

Commit f765eb9

Browse files
committed
feat: cors service
1 parent 50c6a35 commit f765eb9

61 files changed

Lines changed: 927 additions & 639 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ _APP_OPTIONS_FORCE_HTTPS=disabled
2222
_APP_OPTIONS_ROUTER_FORCE_HTTPS=disabled
2323
_APP_OPENSSL_KEY_V1=your-secret-key
2424
_APP_DNS=8.8.8.8
25-
_APP_DOMAIN=traefik
25+
_APP_DOMAIN=appwrite.test
2626
_APP_CONSOLE_DOMAIN=localhost
2727
_APP_DOMAIN_FUNCTIONS=functions.localhost
2828
_APP_DOMAIN_SITES=sites.localhost
@@ -124,4 +124,4 @@ _APP_MESSAGE_PUSH_TEST_DSN=
124124
_APP_WEBHOOK_MAX_FAILED_ATTEMPTS=10
125125
_APP_PROJECT_REGIONS=default
126126
_APP_FUNCTIONS_CREATION_ABUSE_LIMIT=5000
127-
_APP_STATS_USAGE_DUAL_WRITING_DBS=database_db_main
127+
_APP_STATS_USAGE_DUAL_WRITING_DBS=database_db_main

app/config/platform.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use Utopia\System\System;
4+
5+
/**
6+
* Platform configuration
7+
*/
8+
return [
9+
'domain' => System::getEnv('_APP_DOMAIN', 'localhost'),
10+
'consoleDomain' => System::getEnv('_APP_CONSOLE_DOMAIN', System::getEnv('_APP_DOMAIN', 'localhost')),
11+
'platformName' => APP_EMAIL_PLATFORM_NAME,
12+
'logoUrl' => APP_EMAIL_LOGO_URL,
13+
'accentColor' => APP_EMAIL_ACCENT_COLOR,
14+
'footerImageUrl' => APP_EMAIL_FOOTER_IMAGE_URL,
15+
'twitterUrl' => APP_SOCIAL_TWITTER,
16+
'discordUrl' => APP_SOCIAL_DISCORD,
17+
'githubUrl' => APP_SOCIAL_GITHUB,
18+
'termsUrl' => APP_EMAIL_TERMS_URL,
19+
'privacyUrl' => APP_EMAIL_PRIVACY_URL,
20+
'websiteUrl' => 'https://' . APP_DOMAIN,
21+
];

app/config/templates/site.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

3+
use Utopia\Config\Config;
34
use Utopia\System\System;
45

56
/**
67
* List of Appwrite Sites templates
78
*/
89

910
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
10-
$hostname = System::getEnv('_APP_CONSOLE_DOMAIN', '');
11+
$platform = Config::getParam('platform', []);
12+
$hostname = $platform['consoleDomain'] ?? '';
1113

1214
$url = $protocol . '://' . $hostname;
1315

app/controllers/api/account.php

Lines changed: 24 additions & 29 deletions
Large diffs are not rendered by default.

app/controllers/api/console.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@
4343
))
4444
->inject('response')
4545
->action(function (Response $response) {
46-
$validator = new Domain(System::getEnv('_APP_DOMAIN'));
47-
$isDomainValid = !empty(System::getEnv('_APP_DOMAIN', '')) && $validator->isKnown() && !$validator->isTest();
48-
4946
$validator = new Domain(System::getEnv('_APP_DOMAIN_TARGET_CNAME'));
5047
$isCNAMEValid = !empty(System::getEnv('_APP_DOMAIN_TARGET_CNAME', '')) && $validator->isKnown() && !$validator->isTest();
5148

@@ -55,9 +52,7 @@
5552
$validator = new IP(IP::V6);
5653
$isAAAAValid = !empty(System::getEnv('_APP_DOMAIN_TARGET_AAAA', '')) && $validator->isValid(System::getEnv('_APP_DOMAIN_TARGET_AAAA'));
5754

58-
$isDomainEnabled = $isDomainValid && (
59-
$isAAAAValid || $isAValid || $isCNAMEValid
60-
);
55+
$isDomainEnabled = $isAAAAValid || $isAValid || $isCNAMEValid;
6156

6257
$isVcsEnabled = !empty(System::getEnv('_APP_VCS_GITHUB_APP_NAME', ''))
6358
&& !empty(System::getEnv('_APP_VCS_GITHUB_PRIVATE_KEY', ''))

app/controllers/api/messaging.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use Appwrite\Utopia\Database\Validator\Queries\Subscribers;
2424
use Appwrite\Utopia\Database\Validator\Queries\Targets;
2525
use Appwrite\Utopia\Database\Validator\Queries\Topics;
26-
use Appwrite\Utopia\Request;
2726
use Appwrite\Utopia\Response;
2827
use MaxMind\Db\Reader;
2928
use Utopia\App;
@@ -3495,9 +3494,9 @@
34953494
->inject('dbForPlatform')
34963495
->inject('project')
34973496
->inject('queueForMessaging')
3498-
->inject('request')
34993497
->inject('response')
3500-
->action(function (string $messageId, string $title, string $body, ?array $topics, ?array $users, ?array $targets, ?array $data, string $action, string $image, string $icon, string $sound, string $color, string $tag, int $badge, bool $draft, ?string $scheduledAt, bool $contentAvailable, bool $critical, string $priority, Event $queueForEvents, Database $dbForProject, Database $dbForPlatform, Document $project, Messaging $queueForMessaging, Request $request, Response $response) {
3498+
->inject('platform')
3499+
->action(function (string $messageId, string $title, string $body, ?array $topics, ?array $users, ?array $targets, ?array $data, string $action, string $image, string $icon, string $sound, string $color, string $tag, int $badge, bool $draft, ?string $scheduledAt, bool $contentAvailable, bool $critical, string $priority, Event $queueForEvents, Database $dbForProject, Database $dbForPlatform, Document $project, Messaging $queueForMessaging, Response $response, array $platform) {
35013500
$messageId = $messageId == 'unique()'
35023501
? ID::unique()
35033502
: $messageId;
@@ -3573,7 +3572,7 @@
35733572
$image = [
35743573
'bucketId' => $bucket->getId(),
35753574
'fileId' => $file->getId(),
3576-
'url' => "{$protocol}://{$request->getHostname()}/v1/storage/buckets/{$bucket->getId()}/files/{$file->getId()}/push?project={$project->getId()}&jwt={$jwt}",
3575+
'url' => "{$platform['endpoint']}/storage/buckets/{$bucket->getId()}/files/{$file->getId()}/push?project={$project->getId()}&jwt={$jwt}",
35773576
];
35783577
}
35793578

@@ -4378,9 +4377,9 @@
43784377
->inject('dbForPlatform')
43794378
->inject('project')
43804379
->inject('queueForMessaging')
4381-
->inject('request')
43824380
->inject('response')
4383-
->action(function (string $messageId, ?array $topics, ?array $users, ?array $targets, ?string $title, ?string $body, ?array $data, ?string $action, ?string $image, ?string $icon, ?string $sound, ?string $color, ?string $tag, ?int $badge, ?bool $draft, ?string $scheduledAt, ?bool $contentAvailable, ?bool $critical, ?string $priority, Event $queueForEvents, Database $dbForProject, Database $dbForPlatform, Document $project, Messaging $queueForMessaging, Request $request, Response $response) {
4381+
->inject('platform')
4382+
->action(function (string $messageId, ?array $topics, ?array $users, ?array $targets, ?string $title, ?string $body, ?array $data, ?string $action, ?string $image, ?string $icon, ?string $sound, ?string $color, ?string $tag, ?int $badge, ?bool $draft, ?string $scheduledAt, ?bool $contentAvailable, ?bool $critical, ?string $priority, Event $queueForEvents, Database $dbForProject, Database $dbForPlatform, Document $project, Messaging $queueForMessaging, Response $response, array $platform) {
43844383
$message = $dbForProject->getDocument('messages', $messageId);
43854384

43864385
if ($message->isEmpty()) {
@@ -4548,8 +4547,6 @@
45484547
throw new Exception(Exception::STORAGE_FILE_TYPE_UNSUPPORTED);
45494548
}
45504549

4551-
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
4552-
45534550
$scheduleTime = $currentScheduledAt ?? $scheduledAt;
45544551
if (!\is_null($scheduleTime)) {
45554552
$expiry = (new \DateTime($scheduleTime))->add(new \DateInterval('P15D'))->format('U');
@@ -4568,7 +4565,7 @@
45684565
$pushData['image'] = [
45694566
'bucketId' => $bucket->getId(),
45704567
'fileId' => $file->getId(),
4571-
'url' => "{$protocol}://{$request->getHost()}/v1/storage/buckets/{$bucket->getId()}/files/{$file->getId()}/push?project={$project->getId()}&jwt={$jwt}"
4568+
'url' => "{$platform['endpoint']}/storage/buckets/{$bucket->getId()}/files/{$file->getId()}/push?project={$project->getId()}&jwt={$jwt}",
45724569
];
45734570
}
45744571

app/controllers/api/teams.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
use Utopia\Validator\Assoc;
5959
use Utopia\Validator\Boolean;
6060
use Utopia\Validator\Text;
61-
use Utopia\Validator\URL;
6261
use Utopia\Validator\WhiteList;
6362

6463
App::post('/v1/teams')
@@ -486,7 +485,7 @@
486485
}
487486
return new ArrayList(new Key(), APP_LIMIT_ARRAY_PARAMS_SIZE);
488487
}, 'Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](https://appwrite.io/docs/permissions). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' roles are allowed, each 32 characters long.', false, ['project'])
489-
->param('url', '', fn ($platforms, $devKey) => $devKey->isEmpty() ? new Redirect($platforms) : new URL(), 'URL to redirect the user back to your app from the invitation email. This parameter is not required when an API key is supplied. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.', true, ['platforms', 'devKey']) // TODO add our own built-in confirm page
488+
->param('url', '', fn ($redirectValidator) => $redirectValidator, 'URL to redirect the user back to your app from the invitation email. This parameter is not required when an API key is supplied. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.', true, ['redirectValidator']) // TODO add our own built-in confirm page
490489
->param('name', '', new Text(128), 'Name of the new team member. Max length: 128 chars.', true)
491490
->inject('response')
492491
->inject('project')

0 commit comments

Comments
 (0)