Use settings to determine if sign up route is enabled (#51)

This commit is contained in:
sua yoo 2021-12-03 10:05:55 -08:00 committed by GitHub
parent 30e40adddd
commit 87bef6d967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 119 additions and 19 deletions

2
frontend/.env Normal file
View File

@ -0,0 +1,2 @@
API_BASE_URL='https://btrix.webrecorder.net/api'
REGISTRATION_ENABLED=false

View File

@ -19,7 +19,7 @@
},
"scripts": {
"test": "web-test-runner \"src/**/*.test.{ts,js}\" --node-resolve --playwright --browsers chromium",
"prebuild": "npm run localize:build",
"prebuild": "npm run localize:build && npm run get-settings",
"prebuild-dev": "npm run localize:build",
"build": "webpack --mode production",
"build-dev": "webpack --mode development",
@ -27,7 +27,8 @@
"lint": "eslint --fix \"src/**/*.{ts,js}\"",
"format": "prettier --write \"**/*.{ts,js,html,css}\"",
"localize:extract": "lit-localize extract",
"localize:build": "lit-localize build"
"localize:build": "lit-localize build",
"get-settings": "node ./scripts/get-settings.mjs"
},
"devDependencies": {
"@esm-bundle/chai": "^4.3.4-fix.0",
@ -45,11 +46,13 @@
"copy-webpack-plugin": "^9.1.0",
"css-loader": "^6.3.0",
"dotenv": "^10.0.0",
"dotenv-webpack": "^7.0.3",
"eslint": "^8.2.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-lit": "^1.6.1",
"eslint-plugin-wc": "^1.3.2",
"eslint-webpack-plugin": "^3.1.1",
"node-fetch": "^3.1.0",
"postcss": "^8.3.8",
"postcss-loader": "^6.1.1",
"prettier": "^2.4.1",
@ -57,6 +60,7 @@
"style-loader": "^3.3.0",
"ts-loader": "^9.2.6",
"typescript": "^4.5.2",
"update-dotenv": "^1.1.1",
"webpack": "^5.56.0",
"webpack-cli": "^4.8.0",
"webpack-dev-server": "^4.3.0"

View File

@ -1 +1,2 @@
API_BASE_URL='http://btrix.cloud'
REGISTRATION_ENABLED=true

View File

@ -0,0 +1,28 @@
import fetch from "node-fetch";
import updateDotenv from "update-dotenv";
import dotenv from "dotenv";
dotenv.config();
async function main() {
try {
const resp = await fetch(`${process.env.API_BASE_URL}/settings`);
const body = await resp.json();
const newEnv = await updateDotenv({
REGISTRATION_ENABLED: Boolean(body.enabled).toString(),
});
console.log(
".env file updated:",
`REGISTRATION_ENABLED=${newEnv["REGISTRATION_ENABLED"]}`
);
} catch {
console.log(
"could not update .env file, env is now:",
`REGISTRATION_ENABLED=${process.env.REGISTRATION_ENABLED}`
);
}
}
main();

View File

@ -1,17 +1,12 @@
// Do not modify this file by hand!
// Re-generate this file by running lit-localize
// Do not modify this file by hand!
// Re-generate this file by running lit-localize
/* eslint-disable no-irregular-whitespace */
/* eslint-disable @typescript-eslint/no-explicit-any */
export const templates = {
's47d31e4dbe55f7d9': `Browsertrix Cloud`,
'sa03807e44737a915': `로그아웃`,
'sca974356724f8230': `로그인`,
'sd03ac20f93055ed8': `내 계정`,
};
/* eslint-disable no-irregular-whitespace */
/* eslint-disable @typescript-eslint/no-explicit-any */
export const templates = {
s47d31e4dbe55f7d9: `Browsertrix Cloud`,
sa03807e44737a915: `로그아웃`,
sca974356724f8230: `로그인`,
sd03ac20f93055ed8: `내 계정`,
};

View File

@ -26,9 +26,9 @@ import type { CurrentUser } from "./types/user";
import type { AuthState } from "./utils/AuthService";
import theme from "./theme";
const REGISTRATION_ENABLED = process.env.REGISTRATION_ENABLED === "true";
const ROUTES = {
home: "/",
signUp: "/sign-up",
join: "/join/:token?email",
verify: "/verify?token",
login: "/log-in",
@ -40,6 +40,11 @@ const ROUTES = {
archive: "/archives/:id/:tab",
archiveAddMember: "/archives/:id/:tab/add-member",
} as const;
if (REGISTRATION_ENABLED) {
(ROUTES as any).signUp = "/sign-up";
}
const DASHBOARD_ROUTE = ROUTES.archives;
type DialogContent = {

View File

@ -2,13 +2,19 @@
const path = require("path");
const ESLintPlugin = require("eslint-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const Dotenv = require("dotenv-webpack");
const isDevServer = process.env.WEBPACK_SERVE;
const dotEnvPath = path.resolve(
process.cwd(),
`.env${isDevServer ? `.local` : ""}`
);
require("dotenv").config({
path: path.resolve(process.cwd(), `.env${isDevServer ? `.local` : ""}`),
path: dotEnvPath,
});
// TODO actual prod URL
const backendUrl = new URL(process.env.API_BASE_URL || "http://btrix.cloud/");
const shoelaceAssetsSrcPath = path.resolve(
__dirname,
@ -80,6 +86,8 @@ module.exports = {
},
plugins: [
new Dotenv({ path: dotEnvPath }),
// Lint js files
new ESLintPlugin({
// lint only changed files:

View File

@ -1746,6 +1746,11 @@ cssesc@^3.0.0:
resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz#37741919903b868565e1c09ea747445cd18983ee"
integrity sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==
data-uri-to-buffer@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz#b5db46aea50f6176428ac05b73be39a57701a64b"
integrity sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==
debounce@^1.2.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/debounce/-/debounce-1.2.1.tgz#38881d8f4166a5c5848020c11827b834bcb3e0a5"
@ -1935,11 +1940,30 @@ doctrine@^3.0.0:
dependencies:
esutils "^2.0.2"
dotenv-defaults@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/dotenv-defaults/-/dotenv-defaults-2.0.2.tgz#6b3ec2e4319aafb70940abda72d3856770ee77ac"
integrity sha512-iOIzovWfsUHU91L5i8bJce3NYK5JXeAwH50Jh6+ARUdLiiGlYWfGw6UkzsYqaXZH/hjE/eCd/PlfM/qqyK0AMg==
dependencies:
dotenv "^8.2.0"
dotenv-webpack@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/dotenv-webpack/-/dotenv-webpack-7.0.3.tgz#f50ec3c7083a69ec6076e110566720003b7b107b"
integrity sha512-O0O9pOEwrk+n1zzR3T2uuXRlw64QxHSPeNN1GaiNBloQFNaCUL9V8jxSVz4jlXXFP/CIqK8YecWf8BAvsSgMjw==
dependencies:
dotenv-defaults "^2.0.2"
dotenv@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==
dotenv@^8.2.0:
version "8.6.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.6.0.tgz#061af664d19f7f4d8fc6e4ff9b584ce237adcb8b"
integrity sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==
ee-first@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
@ -2321,6 +2345,13 @@ fd-slicer@~1.1.0:
dependencies:
pend "~1.2.0"
fetch-blob@^3.1.2:
version "3.1.3"
resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.1.3.tgz#a7dca4855e39d3e3c5a1da62d4ee335c37d26012"
integrity sha512-ax1Y5I9w+9+JiM+wdHkhBoxew+zG4AJ2SvAD1v1szpddUIiPERVGBxrMcB2ZqW0Y3PP8bOWYv2zqQq1Jp2kqUQ==
dependencies:
web-streams-polyfill "^3.0.3"
file-entry-cache@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027"
@ -2381,6 +2412,13 @@ follow-redirects@^1.0.0, follow-redirects@^1.14.4:
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.4.tgz#838fdf48a8bbdd79e52ee51fb1c94e3ed98b9379"
integrity sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g==
formdata-polyfill@^4.0.10:
version "4.0.10"
resolved "https://registry.yarnpkg.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz#24807c31c9d402e002ab3d8c720144ceb8848423"
integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==
dependencies:
fetch-blob "^3.1.2"
forwarded@0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/forwarded/-/forwarded-0.2.0.tgz#2269936428aad4c15c7ebe9779a84bf0b2a81811"
@ -3505,6 +3543,15 @@ node-fetch@2.6.5:
dependencies:
whatwg-url "^5.0.0"
node-fetch@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.1.0.tgz#714f4922dc270239487654eaeeab86b8206cb52e"
integrity sha512-QU0WbIfMUjd5+MUzQOYhenAazakV7Irh1SGkWCsRzBwvm4fAhzEUaHMJ6QLP7gWT6WO9/oH2zhKMMGMuIrDyKw==
dependencies:
data-uri-to-buffer "^4.0.0"
fetch-blob "^3.1.2"
formdata-polyfill "^4.0.10"
node-forge@^0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.10.0.tgz#32dea2afb3e9926f02ee5ce8794902691a676bf3"
@ -4828,6 +4875,11 @@ unpipe@1.0.0, unpipe@~1.0.0:
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
integrity sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=
update-dotenv@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/update-dotenv/-/update-dotenv-1.1.1.tgz#17146f302f216c3c92419d5a327a45be910050ca"
integrity sha512-3cIC18In/t0X/yH793c00qqxcKD8jVCgNOPif/fGQkFpYMGecM9YAc+kaAKXuZsM2dE9I9wFI7KvAuNX22SGMQ==
uri-js@^4.2.2:
version "4.4.1"
resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e"
@ -4892,6 +4944,11 @@ wbuf@^1.1.0, wbuf@^1.7.3:
dependencies:
minimalistic-assert "^1.0.0"
web-streams-polyfill@^3.0.3:
version "3.2.0"
resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.0.tgz#a6b74026b38e4885869fb5c589e90b95ccfc7965"
integrity sha512-EqPmREeOzttaLRm5HS7io98goBgZ7IVz79aDvqjD0kYXLtFZTc0T/U6wHTPKyIjb+MdN7DFIIX6hgdBEpWmfPA==
webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"