diff --git a/bin/backup-mastodon-data.sh b/bin/backup-mastodon-data.sh new file mode 100755 index 00000000..525b889e --- /dev/null +++ b/bin/backup-mastodon-data.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -x +set -e + +PGPASSWORD=pinafore pg_dump -U pinafore -w pinafore_development > fixtures/dump.sql +cd mastodon/public/system +tar -czf ../../../fixtures/system.tgz . diff --git a/bin/deploy-all-travis.sh b/bin/deploy-all-travis.sh new file mode 100755 index 00000000..d5b1f8d4 --- /dev/null +++ b/bin/deploy-all-travis.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -e +set -x + +if [ "$TRAVIS_BRANCH" = master -a "$TRAVIS_PULL_REQUEST" = false ]; then + npm run deploy-dev +fi diff --git a/bin/deploy.sh b/bin/deploy.sh new file mode 100755 index 00000000..11b1fb4f --- /dev/null +++ b/bin/deploy.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +set -e +set -x + +PATH="$PATH:./node_modules/.bin" + +# set up robots.txt +if [[ "$DEPLOY_TYPE" == "prod" ]]; then + printf 'User-agent: *\nDisallow: /' > assets/robots.txt +else + rm -f assets/robots.txt +fi + +# if in travis, use the $NOW_TOKEN +NOW_COMMAND="now --team nolanlawson" +if [[ ! -z "$NOW_TOKEN" ]]; then + NOW_COMMAND="$NOW_COMMAND --token $NOW_TOKEN" +fi + +#launch +$NOW_COMMAND -e SAPPER_TIMESTAMP=$(date +%s%3N) + +# fixes issues with now being unavailable immediately +sleep 60 + +# choose the right alias +NOW_ALIAS="dev.pinafore.social" + +if [[ "$DEPLOY_TYPE" == "prod" ]]; then + NOW_ALIAS="pinafore.social" +fi + +# alias +$NOW_COMMAND alias "$NOW_ALIAS" + +# cleanup +$NOW_COMMAND rm pinafore --safe --yes diff --git a/package.json b/package.json index df895b62..10bb3105 100644 --- a/package.json +++ b/package.json @@ -33,22 +33,10 @@ "wait-for-mastodon-data": "node -r esm bin/wait-for-mastodon-data.js", "globalize-css": "node ./bin/globalize-css.js", "deglobalize-css": "node ./bin/globalize-css.js --reverse", - "stage-dev": "printf 'User-agent: *\nDisallow: /' > assets/robots.txt", - "stage-prod": "rm -f assets/robots.txt", - "launch": "now -e SAPPER_TIMESTAMP=$(date +%s%3N) --team nolanlawson && sleep 60", - "launch-travis": "now -e SAPPER_TIMESTAMP=$(date +%s%3N) --team nolanlawson --token $NOW_TOKEN && sleep 60", - "alias-prod": "now alias pinafore.social --team nolanlawson", - "alias-prod-travis": "now alias pinafore.social --team nolanlawson --token $NOW_TOKEN", - "alias-dev": "now alias dev.pinafore.social --team nolanlawson", - "alias-dev-travis": "now alias dev.pinafore.social --team nolanlawson --token $NOW_TOKEN", - "cleanup": "now rm pinafore --safe --yes --team nolanlawson", - "cleanup-travis": "now rm pinafore --safe --yes --team nolanlawson --token $NOW_TOKEN", - "deploy-prod": "run-s stage-prod launch alias-prod cleanup", - "deploy-dev": "run-s stage-dev launch alias-dev cleanup", - "deploy-dev-travis": "run-s stage-dev launch-travis alias-dev-travis cleanup-travis; fi", - "deploy-prod-travis": "if echo $TRAVIS_COMMIT_MESSAGE | grep -q -E '\\d+\\.\\d+\\.\\d+'; then run-s stage-prod launch-travis alias-prod-travis cleanup-travis; fi", - "deploy-all-travis": "if [ $TRAVIS_BRANCH = master -a $TRAVIS_PULL_REQUEST = false ]; then run-s deploy-dev-travis deploy-prod-travis; fi", - "backup-mastodon-data": "PGPASSWORD=pinafore pg_dump -U pinafore -w pinafore_development > fixtures/dump.sql && cd mastodon/public/system && tar -czf ../../../fixtures/system.tgz ." + "deploy-prod": "DEPLOY_TYPE=prod ./bin/deploy.sh", + "deploy-dev": "DEPLOY_TYPE=dev ./bin/deploy.sh", + "deploy-all-travis": "./bin/deploy-all-travis.sh", + "backup-mastodon-data": "./bin/backup-mastodon-data.sh" }, "dependencies": { "@gamestdio/websocket": "^0.2.8", diff --git a/routes/_api/utils.js b/routes/_api/utils.js index 73b1a4bd..654f5180 100644 --- a/routes/_api/utils.js +++ b/routes/_api/utils.js @@ -1,13 +1,9 @@ -const isLocalhost = !process.browser || - location.hostname === 'localhost' || - location.hostname === '127.0.0.1' - function targetIsLocalhost (instanceName) { return instanceName.startsWith('localhost:') || instanceName.startsWith('127.0.0.1:') } export function basename (instanceName) { - if (isLocalhost && targetIsLocalhost(instanceName)) { + if (targetIsLocalhost(instanceName)) { return `http://${instanceName}` } return `https://${instanceName}`