diff --git a/make_env.sh b/make_env.sh index f0e5b71a..7e424f3b 100644 --- a/make_env.sh +++ b/make_env.sh @@ -51,7 +51,7 @@ ENV_FILE_SVELTE=./srcs/requirements/svelte/api_front/.env echo "PORT=3000" >> "$ENV_FILE_DOCKER" echo "TWO_FACTOR_AUTHENTICATION_APP_NAME=Transcendance" >> "$ENV_FILE_DOCKER" echo "TICKET_FOR_PLAYING_GAME_SECRET=$(generate_password)" >> "$ENV_FILE_DOCKER" - sed 's/^WEBSITE_/PUBLIC_&/' "$ENV_FILE_DOCKER" | grep "PUBLIC_" > "$ENV_FILE_SVELTE" + grep "WEBSITE_" > "$ENV_FILE_SVELTE" } function choose_options_and_process { @@ -68,8 +68,7 @@ ENV_FILE_SVELTE=./srcs/requirements/svelte/api_front/.env make_env_for_docker_and_svelte else if [ ! -f "$ENV_FILE_SVELTE" ]; then - sed 's/^WEBSITE_/PUBLIC_&/' "$ENV_FILE_DOCKER" | grep "PUBLIC_" > "$ENV_FILE_SVELTE" - + grep "WEBSITE_" > "$ENV_FILE_SVELTE" fi echo "The file $ENV_FILE_DOCKER will not be overwritten. The script will exit." exit 0 diff --git a/srcs/docker-compose.yml b/srcs/docker-compose.yml index 7f3945c2..acd95663 100644 --- a/srcs/docker-compose.yml +++ b/srcs/docker-compose.yml @@ -39,8 +39,6 @@ services: dockerfile: Dockerfile environment: NODE_ENV: "${NODE_ENV}" - WEBSITE_HOST: "${WEBSITE_HOST}" - WEBSITE_PORT: "${WEBSITE_PORT}" restart: unless-stopped ports: - "8042:8042" diff --git a/srcs/requirements/svelte/api_front/README.md b/srcs/requirements/svelte/api_front/README.md deleted file mode 100644 index 43e08d6a..00000000 --- a/srcs/requirements/svelte/api_front/README.md +++ /dev/null @@ -1,107 +0,0 @@ -# This repo is no longer maintained. Consider using `npm init vite` and selecting the `svelte` option or — if you want a full-fledged app framework and don't mind using pre-1.0 software — use [SvelteKit](https://kit.svelte.dev), the official application framework for Svelte. - ---- - -# svelte app - -This is a project template for [Svelte](https://svelte.dev) apps. It lives at https://github.com/sveltejs/template. - -To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit): - -```bash -npx degit sveltejs/template svelte-app -cd svelte-app -``` - -*Note that you will need to have [Node.js](https://nodejs.org) installed.* - - -## Get started - -Install the dependencies... - -```bash -cd svelte-app -npm install -``` - -...then start [Rollup](https://rollupjs.org): - -```bash -npm run dev -``` - -Navigate to [localhost:8080](http://localhost:8080). You should see your app running. Edit a component file in `src`, save it, and reload the page to see your changes. - -By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the `sirv` commands in package.json to include the option `--host 0.0.0.0`. - -If you're using [Visual Studio Code](https://code.visualstudio.com/) we recommend installing the official extension [Svelte for VS Code](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). If you are using other editors you may need to install a plugin in order to get syntax highlighting and intellisense. - -## Building and running in production mode - -To create an optimised version of the app: - -```bash -npm run build -``` - -You can run the newly built app with `npm run start`. This uses [sirv](https://github.com/lukeed/sirv), which is included in your package.json's `dependencies` so that the app will work when you deploy to platforms like [Heroku](https://heroku.com). - - -## Single-page app mode - -By default, sirv will only respond to requests that match files in `public`. This is to maximise compatibility with static fileservers, allowing you to deploy your app anywhere. - -If you're building a single-page app (SPA) with multiple routes, sirv needs to be able to respond to requests for *any* path. You can make it so by editing the `"start"` command in package.json: - -```js -"start": "sirv public --single" -``` - -## Using TypeScript - -This template comes with a script to set up a TypeScript development environment, you can run it immediately after cloning the template with: - -```bash -node scripts/setupTypeScript.js -``` - -Or remove the script via: - -```bash -rm scripts/setupTypeScript.js -``` - -If you want to use `baseUrl` or `path` aliases within your `tsconfig`, you need to set up `@rollup/plugin-alias` to tell Rollup to resolve the aliases. For more info, see [this StackOverflow question](https://stackoverflow.com/questions/63427935/setup-tsconfig-path-in-svelte). - -## Deploying to the web - -### With [Vercel](https://vercel.com) - -Install `vercel` if you haven't already: - -```bash -npm install -g vercel -``` - -Then, from within your project folder: - -```bash -cd public -vercel deploy --name my-project -``` - -### With [surge](https://surge.sh/) - -Install `surge` if you haven't already: - -```bash -npm install -g surge -``` - -Then, from within your project folder: - -```bash -npm run build -surge public my-project.surge.sh -``` diff --git a/srcs/requirements/svelte/api_front/package-lock.json b/srcs/requirements/svelte/api_front/package-lock.json index 943549d1..3f6ceb5a 100644 --- a/srcs/requirements/svelte/api_front/package-lock.json +++ b/srcs/requirements/svelte/api_front/package-lock.json @@ -8,6 +8,7 @@ "name": "svelte-app", "version": "1.0.0", "dependencies": { + "@rollup/plugin-replace": "^5.0.2", "dotenv": "^16.0.3", "sirv-cli": "^2.0.0", "socket.io-client": "^4.5.4", @@ -111,8 +112,7 @@ "node_modules/@jridgewell/sourcemap-codec": { "version": "1.4.14", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", - "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", - "dev": true + "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==" }, "node_modules/@jridgewell/trace-mapping": { "version": "0.3.17", @@ -205,6 +205,63 @@ "rollup": "^1.20.0||^2.0.0" } }, + "node_modules/@rollup/plugin-replace": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-5.0.2.tgz", + "integrity": "sha512-M9YXNekv/C/iHHK+cvORzfRYfPbq0RDD8r0G+bMiTXjNGKulPnCT9O3Ss46WfhI6ZOCgApOP7xAdmCQJ+U2LAA==", + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "magic-string": "^0.27.0" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/plugin-replace/node_modules/@rollup/pluginutils": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.2.tgz", + "integrity": "sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==", + "dependencies": { + "@types/estree": "^1.0.0", + "estree-walker": "^2.0.2", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/plugin-replace/node_modules/@types/estree": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.0.tgz", + "integrity": "sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==" + }, + "node_modules/@rollup/plugin-replace/node_modules/magic-string": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.27.0.tgz", + "integrity": "sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.4.13" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/@rollup/plugin-typescript": { "version": "8.5.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-8.5.0.tgz", @@ -590,8 +647,7 @@ "node_modules/estree-walker": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", - "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", - "dev": true + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==" }, "node_modules/fast-glob": { "version": "3.2.12", @@ -1066,7 +1122,6 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", - "dev": true, "engines": { "node": ">=8.6" }, @@ -1181,7 +1236,7 @@ "version": "2.79.1", "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.1.tgz", "integrity": "sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==", - "dev": true, + "devOptional": true, "bin": { "rollup": "dist/bin/rollup" }, diff --git a/srcs/requirements/svelte/api_front/package.json b/srcs/requirements/svelte/api_front/package.json index 0fcd7ed5..c04c5e50 100644 --- a/srcs/requirements/svelte/api_front/package.json +++ b/srcs/requirements/svelte/api_front/package.json @@ -26,6 +26,7 @@ "typescript": "^4.0.0" }, "dependencies": { + "@rollup/plugin-replace": "^5.0.2", "dotenv": "^16.0.3", "sirv-cli": "^2.0.0", "socket.io-client": "^4.5.4", diff --git a/srcs/requirements/svelte/api_front/rollup.config.js b/srcs/requirements/svelte/api_front/rollup.config.js index 2f0a7243..13c5c99b 100644 --- a/srcs/requirements/svelte/api_front/rollup.config.js +++ b/srcs/requirements/svelte/api_front/rollup.config.js @@ -6,8 +6,13 @@ import { terser } from 'rollup-plugin-terser'; import sveltePreprocess from 'svelte-preprocess'; import typescript from '@rollup/plugin-typescript'; import css from 'rollup-plugin-css-only'; +import replace from '@rollup/plugin-replace'; +import dotenv from 'dotenv'; + const production = !process.env.ROLLUP_WATCH; +dotenv.config(); + function serve() { let server; @@ -47,6 +52,10 @@ export default { dev: !production } }), + replace({ + 'process.env.WEBSITE_HOST': `'${process.env.WEBSITE_HOST}'`, + 'process.env.WEBSITE_PORT': `'${process.env.WEBSITE_PORT}'`, + }), // we'll extract any component CSS out into // a separate file - better for performance css({ output: 'bundle.css' }), diff --git a/srcs/requirements/svelte/api_front/src/pages/SplashPage.svelte b/srcs/requirements/svelte/api_front/src/pages/SplashPage.svelte index 0c15d65f..0ce16e00 100644 --- a/srcs/requirements/svelte/api_front/src/pages/SplashPage.svelte +++ b/srcs/requirements/svelte/api_front/src/pages/SplashPage.svelte @@ -2,7 +2,6 @@ import Canvas from "../pieces/Canvas.svelte"; import { push } from "svelte-spa-router"; import { onMount } from 'svelte'; - import { get } from "svelte/store"; let user; diff --git a/srcs/requirements/svelte/api_front/src/pages/TwoFactorAuthentication.svelte b/srcs/requirements/svelte/api_front/src/pages/TwoFactorAuthentication.svelte index 67908a2d..be30e387 100644 --- a/srcs/requirements/svelte/api_front/src/pages/TwoFactorAuthentication.svelte +++ b/srcs/requirements/svelte/api_front/src/pages/TwoFactorAuthentication.svelte @@ -1,7 +1,7 @@