mirror of
https://github.com/Unkn0wnCat/KevinK.dev.js.git
synced 2025-06-03 11:12:06 +02:00
Remove deprecated code
This commit is contained in:
parent
5e4bfe8a7c
commit
03119444a1
2 changed files with 0 additions and 89 deletions
|
@ -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(),
|
||||
},
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue