diff --git a/fab.config.json5 b/fab.config.json5 deleted file mode 100644 index 0f04ad1..0000000 --- a/fab.config.json5 +++ /dev/null @@ -1,31 +0,0 @@ -// For more information, see https://fab.dev/kb/configuration -{ - plugins: { - './src/server/languageRedirect.js': {}, - '@fab/input-static': { - dir: 'public' - }, - '@fab/plugin-render-html': { - fallback: false - }, - '@fab/plugin-rewire-assets': {} - // This section defines your build & runtime toolchains. See https://fab.dev/kb/plugins - }, - settings: { - // This section defines the variables that are injected, depending on environment. - // See https://fab.dev/kb/settings for more info. - production: { - // This environment is special. These variables get compiled into the FAB itself, - // allowing for many production-specific optimisations. See https://fab.dev/kb/production - // Example setting: - // API_URL: 'https://api.example.com/graphql' - } - }, - deploy: { - // For manual (command-line) deploys, add configuration here. - // • See https://fab.dev/guides/deploying for more info. - // However, we recommend automatic deploys (triggered by git push) - // using a service such as Linc (https://linc.sh) - // • See https://fab.dev/kb/automatic-deploys for setup instructions. - } -} diff --git a/src/server/languageRedirect.js b/src/server/languageRedirect.js deleted file mode 100644 index d246fec..0000000 --- a/src/server/languageRedirect.js +++ /dev/null @@ -1,58 +0,0 @@ -/* eslint-disable no-undef */ -const config = require("../../config"); -const locale = require("locale"); - -let supported = new locale.Locales(config.languages); -let defaultLang = "en"; - -export default ({ Router }) => { - Router.on("*", checkLang); -}; - -async function checkLang({ request }) { - const { url } = request - - // eslint-disable-next-line no-undef - let requestURL = new URL(url); - - if (requestURL.pathname.startsWith("/assets") || - requestURL.pathname.startsWith("/icons") || - requestURL.pathname.startsWith("/manifest.webmanifest") || - requestURL.pathname.startsWith("/favicon") || - requestURL.pathname.startsWith("/sw.js") || - requestURL.pathname.startsWith("/api")) { - - return; - } - - for (let i = 0; i < config.languages.length; i++) { - const language = config.languages[i]; - - if (requestURL.pathname.startsWith("/" + language)) { - return; - } - } - - let headers = request.headers; - - let selectedLanguage = defaultLang; - - if (headers.has("Accept-Language")) { - let languageHeader = headers.get("Accept-Language"); - - let requestLocales = new locale.Locales(languageHeader); - - selectedLanguage = requestLocales.best(supported); - } - - requestURL.pathname = "/" + selectedLanguage + requestURL.pathname; - - ///return Response.redirect(requestURL.toString(), 302); - - return new Response(null, { - status: 302, - headers: { - Location: requestURL.toString(), - }, - }); -}