diff --git a/next-i18next.config.js b/next-i18next.config.js index 8690fad..fa901cf 100644 --- a/next-i18next.config.js +++ b/next-i18next.config.js @@ -1,12 +1,10 @@ //next-i18next.config.js module.exports = { - // debug: true, i18n: { defaultLocale: 'zh', locales: ['zh', 'en'], }, - // eslint-disable-next-line @typescript-eslint/no-var-requires localePath: require('path').resolve('./public/locales'), // 指定翻译文件的路径 }; diff --git a/next.config.js b/next.config.js index 38a9eab..7ae00a7 100644 --- a/next.config.js +++ b/next.config.js @@ -9,12 +9,11 @@ const { i18n } = require('./next-i18next.config'); module.exports = withBundleAnalyzer({ i18n, + reactStrictMode: true, + compress: true, // 启用压缩 eslint: { dirs: ['src'], }, - - reactStrictMode: false, - // Uncoment to add domain whitelist images: { domains: [ @@ -43,11 +42,10 @@ module.exports = withBundleAnalyzer({ test: /\.md$/, use: 'raw-loader', }); - return config; }, - // experimental: { + // disableOptimizedLoading: true, // scrollRestoration: true, // }, }); diff --git a/package.json b/package.json index fdff335..067bad4 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "next": "^12.1.6", "next-i18next": "^15.3.0", "nprogress": "^0.2.0", - "pino-http": "^8.2.1", "raw-loader": "^4.0.2", "rc-image": "^7.0.0-2", "rc-util": "^5.34.1", diff --git a/server.js b/server.js index 13466dd..f067278 100644 --- a/server.js +++ b/server.js @@ -1,42 +1,37 @@ /* eslint-disable @typescript-eslint/no-var-requires */ +const express = require('express'); const next = require('next'); + const dev = process.env.NEXT_PUBLIC_ENV !== 'production'; const app = next({ dev }); const handle = app.getRequestHandler(); -const { parse } = require('url'); - -const express = require('express'); -const expressRouter = express.Router(); -const server = express(); -// this is the logger for the server -var logger = require('pino-http')(); +const PORT = process.env.PORT || 3000; -const NODE_PORT = process.env.NODE_PORT | 3000; +async function startServer() { + try { + await app.prepare(); + const server = express(); -app.prepare().then(() => { - expressRouter.get('*', (req, res) => { - // 页面路由 - logger(req, res); - const parsedUrl = parse(req.url, true); - const { pathname, query } = parsedUrl; - if (pathname.length > 1 && pathname.endsWith('/')) { - return app.render(req, res, pathname.slice(0, -1), query); - } else { - return app.render(req, res, pathname, query); - } - }); - server.use('/', expressRouter); + // 中间件处理尾部斜杠但不重定向 + server.use((req, res, next) => { + if (req.url.length > 1 && req.url.endsWith('/')) { + req.url = req.url.slice(0, -1); + } + next(); + }); - server.all('*', (req, res) => { - // Be sure to pass `true` as the second argument to `url.parse`. - // This tells it to parse the query portion of the URL. - const parsedUrl = parse(req.url, true); + // 处理所有其他请求 + server.all('*', (req, res) => handle(req, res)); - return handle(req, res, parsedUrl); - }); + server.listen(PORT, (err) => { + if (err) throw err; + console.log(`> Ready on http://localhost:${PORT}`); + }); + } catch (error) { + console.error('Error starting server:', error); + process.exit(1); + } +} - server.listen(NODE_PORT, () => - console.log('App listening on port ' + NODE_PORT) - ); -}); +startServer(); diff --git a/src/pages/repository/[rid]/index.tsx b/src/pages/repository/[rid]/index.tsx index e5dd949..08a372a 100644 --- a/src/pages/repository/[rid]/index.tsx +++ b/src/pages/repository/[rid]/index.tsx @@ -42,7 +42,7 @@ const RepositoryPage: NextPage = ({ repo }) => { t={t} i18n_lang={i18n.language} /> -
+
); }; diff --git a/yarn.lock b/yarn.lock index 861b1b9..51047e4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2157,13 +2157,6 @@ abab@^2.0.3, abab@^2.0.5: resolved "https://registry.npmmirror.com/abab/-/abab-2.0.6.tgz" integrity sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA== -abort-controller@^3.0.0: - version "3.0.0" - resolved "https://registry.npmmirror.com/abort-controller/-/abort-controller-3.0.0.tgz" - integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg== - dependencies: - event-target-shim "^5.0.0" - accepts@~1.3.8: version "1.3.8" resolved "https://registry.npmmirror.com/accepts/-/accepts-1.3.8.tgz" @@ -2399,11 +2392,6 @@ asynckit@^0.4.0: resolved "https://registry.npmmirror.com/asynckit/-/asynckit-0.4.0.tgz" integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q== -atomic-sleep@^1.0.0: - version "1.0.0" - resolved "https://registry.npmmirror.com/atomic-sleep/-/atomic-sleep-1.0.0.tgz" - integrity sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ== - autoprefixer@^10.4.7: version "10.4.12" resolved "https://registry.npmmirror.com/autoprefixer/-/autoprefixer-10.4.12.tgz" @@ -2535,11 +2523,6 @@ balanced-match@^1.0.0: resolved "https://registry.npmmirror.com/balanced-match/-/balanced-match-1.0.2.tgz" integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== -base64-js@^1.3.1: - version "1.5.1" - resolved "https://registry.npmmirror.com/base64-js/-/base64-js-1.5.1.tgz" - integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== - big.js@^5.2.2: version "5.2.2" resolved "https://registry.npmmirror.com/big.js/-/big.js-5.2.2.tgz" @@ -2615,14 +2598,6 @@ buffer-from@^1.0.0: resolved "https://registry.npmmirror.com/buffer-from/-/buffer-from-1.1.2.tgz" integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== -buffer@^6.0.3: - version "6.0.3" - resolved "https://registry.npmmirror.com/buffer/-/buffer-6.0.3.tgz" - integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA== - dependencies: - base64-js "^1.3.1" - ieee754 "^1.2.1" - bytes@3.1.2: version "3.1.2" resolved "https://registry.npmmirror.com/bytes/-/bytes-3.1.2.tgz" @@ -3888,16 +3863,6 @@ etag@~1.8.1: resolved "https://registry.npmmirror.com/etag/-/etag-1.8.1.tgz" integrity sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg== -event-target-shim@^5.0.0: - version "5.0.1" - resolved "https://registry.npmmirror.com/event-target-shim/-/event-target-shim-5.0.1.tgz" - integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ== - -events@^3.3.0: - version "3.3.0" - resolved "https://registry.npmmirror.com/events/-/events-3.3.0.tgz" - integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q== - execa@^5.0.0, execa@^5.1.1: version "5.1.1" resolved "https://registry.npmmirror.com/execa/-/execa-5.1.1.tgz" @@ -4012,18 +3977,6 @@ fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6: resolved "https://registry.npmmirror.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz" integrity sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw== -fast-redact@^3.1.1: - version "3.1.2" - resolved "https://registry.npmmirror.com/fast-redact/-/fast-redact-3.1.2.tgz" - integrity sha512-+0em+Iya9fKGfEQGcd62Yv6onjBmmhV1uh86XVfOU8VwAe6kaFdQCWI9s0/Nnugx5Vd9tdbZ7e6gE2tR9dzXdw== - -fast-url-parser@^1.1.3: - version "1.1.3" - resolved "https://registry.npmmirror.com/fast-url-parser/-/fast-url-parser-1.1.3.tgz" - integrity sha512-5jOCVXADYNuRkKFzNJ0dCCewsZiYo0dz8QNYljkOpFC6r2U4OBmKtvm/Tsuh4w1YYdDqDb31a8TVhBJ2OJKdqQ== - dependencies: - punycode "^1.3.2" - fastq@^1.6.0: version "1.13.0" resolved "https://registry.npmmirror.com/fastq/-/fastq-1.13.0.tgz" @@ -4536,11 +4489,6 @@ iconv-lite@0.4.24: dependencies: safer-buffer ">= 2.1.2 < 3" -ieee754@^1.2.1: - version "1.2.1" - resolved "https://registry.npmmirror.com/ieee754/-/ieee754-1.2.1.tgz" - integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== - ignore@^5.2.0: version "5.2.0" resolved "https://registry.npmmirror.com/ignore/-/ignore-5.2.0.tgz" @@ -6252,11 +6200,6 @@ object.values@^1.1.5: define-properties "^1.1.3" es-abstract "^1.19.1" -on-exit-leak-free@^2.1.0: - version "2.1.0" - resolved "https://registry.npmmirror.com/on-exit-leak-free/-/on-exit-leak-free-2.1.0.tgz" - integrity sha512-VuCaZZAjReZ3vUwgOB8LxAosIurDiAW0s13rI1YwmaP++jvcxP77AWoQvenZebpCA2m8WC1/EosPYPMjnRAp/w== - on-finished@2.4.1: version "2.4.1" resolved "https://registry.npmmirror.com/on-finished/-/on-finished-2.4.1.tgz" @@ -6487,47 +6430,6 @@ pify@^3.0.0: resolved "https://registry.npmmirror.com/pify/-/pify-3.0.0.tgz" integrity sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg== -pino-abstract-transport@v1.0.0: - version "1.0.0" - resolved "https://registry.npmmirror.com/pino-abstract-transport/-/pino-abstract-transport-1.0.0.tgz" - integrity sha512-c7vo5OpW4wIS42hUVcT5REsL8ZljsUfBjqV/e2sFxmFEFZiq1XLUp5EYLtuDH6PEHq9W1egWqRbnLUP5FuZmOA== - dependencies: - readable-stream "^4.0.0" - split2 "^4.0.0" - -pino-http@^8.2.1: - version "8.2.1" - resolved "https://registry.npmmirror.com/pino-http/-/pino-http-8.2.1.tgz" - integrity sha512-bdWAE4HYfFjDhKw2/N7BLNSIFAs+WDLZnetsGRpBdNEKq7/RoZUgblLS5OlMY257RPQml6J5QiiLkwxbstzWbA== - dependencies: - fast-url-parser "^1.1.3" - get-caller-file "^2.0.5" - pino "^8.0.0" - pino-std-serializers "^6.0.0" - process-warning "^2.0.0" - -pino-std-serializers@^6.0.0: - version "6.0.0" - resolved "https://registry.npmmirror.com/pino-std-serializers/-/pino-std-serializers-6.0.0.tgz" - integrity sha512-mMMOwSKrmyl+Y12Ri2xhH1lbzQxwwpuru9VjyJpgFIH4asSj88F2csdMwN6+M5g1Ll4rmsYghHLQJw81tgZ7LQ== - -pino@^8.0.0: - version "8.6.1" - resolved "https://registry.npmmirror.com/pino/-/pino-8.6.1.tgz" - integrity sha512-fi+V2K98eMZjQ/uEHHSiMALNrz7HaFdKNYuyA3ZUrbH0f1e8sPFDmeRGzg7ZH2q4QDxGnJPOswmqlEaTAZeDPA== - dependencies: - atomic-sleep "^1.0.0" - fast-redact "^3.1.1" - on-exit-leak-free "^2.1.0" - pino-abstract-transport v1.0.0 - pino-std-serializers "^6.0.0" - process-warning "^2.0.0" - quick-format-unescaped "^4.0.3" - real-require "^0.2.0" - safe-stable-stringify "^2.3.1" - sonic-boom "^3.1.0" - thread-stream "^2.0.0" - pirates@^4.0.4: version "4.0.5" resolved "https://registry.npmmirror.com/pirates/-/pirates-4.0.5.tgz" @@ -6662,16 +6564,6 @@ process-nextick-args@~2.0.0: resolved "https://registry.npmmirror.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz" integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag== -process-warning@^2.0.0: - version "2.0.0" - resolved "https://registry.npmmirror.com/process-warning/-/process-warning-2.0.0.tgz" - integrity sha512-+MmoAXoUX+VTHAlwns0h+kFUWFs/3FZy+ZuchkgjyOu3oioLAo2LB5aCfKPh2+P9O18i3m43tUEv3YqttSy0Ww== - -process@^0.11.10: - version "0.11.10" - resolved "https://registry.npmmirror.com/process/-/process-0.11.10.tgz" - integrity sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A== - prompts@^2.0.1: version "2.4.2" resolved "https://registry.npmmirror.com/prompts/-/prompts-2.4.2.tgz" @@ -6714,11 +6606,6 @@ psl@^1.1.33: resolved "https://registry.npmmirror.com/psl/-/psl-1.9.0.tgz" integrity sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag== -punycode@^1.3.2: - version "1.4.1" - resolved "https://registry.npmmirror.com/punycode/-/punycode-1.4.1.tgz" - integrity sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ== - punycode@^2.1.0, punycode@^2.1.1: version "2.1.1" resolved "https://registry.npmmirror.com/punycode/-/punycode-2.1.1.tgz" @@ -6746,11 +6633,6 @@ queue-microtask@^1.2.2: resolved "https://registry.npmmirror.com/queue-microtask/-/queue-microtask-1.2.3.tgz" integrity sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A== -quick-format-unescaped@^4.0.3: - version "4.0.4" - resolved "https://registry.npmmirror.com/quick-format-unescaped/-/quick-format-unescaped-4.0.4.tgz" - integrity sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg== - quick-lru@^4.0.1: version "4.0.1" resolved "https://registry.npmmirror.com/quick-lru/-/quick-lru-4.0.1.tgz" @@ -6834,7 +6716,7 @@ rc-util@^5.0.6, rc-util@^5.21.0, rc-util@^5.8.0: react-is "^16.12.0" shallowequal "^1.1.0" -rc-util@^5.24.4, rc-util@^5.34.1: +rc-util@^5.24.4: version "5.34.1" resolved "https://registry.npmjs.org/rc-util/-/rc-util-5.34.1.tgz" integrity sha512-SqiUT8Ssgh5C+hu4y887xwCrMNcxLm6ScOo8AFlWYYF3z9uNNiPpwwSjvicqOlWd79rNw1g44rnP7tz9MrO1ZQ== @@ -6842,6 +6724,14 @@ rc-util@^5.24.4, rc-util@^5.34.1: "@babel/runtime" "^7.18.3" react-is "^16.12.0" +rc-util@^5.34.1: + version "5.43.0" + resolved "https://registry.yarnpkg.com/rc-util/-/rc-util-5.43.0.tgz#bba91fbef2c3e30ea2c236893746f3e9b05ecc4c" + integrity sha512-AzC7KKOXFqAdIBqdGWepL9Xn7cm3vnAmjlHqUnoQaTMZYhM4VlXGLkkHHxj/BZ7Td0+SOPKB4RGPboBVKT9htw== + dependencies: + "@babel/runtime" "^7.18.3" + react-is "^18.2.0" + react-dom@^18.1.0: version "18.2.0" resolved "https://registry.npmmirror.com/react-dom/-/react-dom-18.2.0.tgz" @@ -6890,6 +6780,11 @@ react-is@^18.0.0: resolved "https://registry.npmmirror.com/react-is/-/react-is-18.2.0.tgz" integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w== +react-is@^18.2.0: + version "18.3.1" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e" + integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg== + react-markdown@^8.0.3: version "8.0.3" resolved "https://registry.npmmirror.com/react-markdown/-/react-markdown-8.0.3.tgz" @@ -6981,16 +6876,6 @@ readable-stream@3, readable-stream@^3.0.0, readable-stream@^3.0.2: string_decoder "^1.1.1" util-deprecate "^1.0.1" -readable-stream@^4.0.0: - version "4.2.0" - resolved "https://registry.npmmirror.com/readable-stream/-/readable-stream-4.2.0.tgz" - integrity sha512-gJrBHsaI3lgBoGMW/jHZsQ/o/TIWiu5ENCJG1BB7fuCKzpFM8GaS2UoBVt9NO+oI+3FcrBNbUkl3ilDe09aY4A== - dependencies: - abort-controller "^3.0.0" - buffer "^6.0.3" - events "^3.3.0" - process "^0.11.10" - readable-stream@~2.3.6: version "2.3.7" resolved "https://registry.npmmirror.com/readable-stream/-/readable-stream-2.3.7.tgz" @@ -7011,11 +6896,6 @@ readdirp@~3.6.0: dependencies: picomatch "^2.2.1" -real-require@^0.2.0: - version "0.2.0" - resolved "https://registry.npmmirror.com/real-require/-/real-require-0.2.0.tgz" - integrity sha512-57frrGM/OCTLqLOAh0mhVA9VBMHd+9U7Zb2THMGdBUoZVOtGbJzjxsYGDJ3A9AYYCP4hn6y1TVbaOfzWtm5GFg== - redent@^3.0.0: version "3.0.0" resolved "https://registry.npmmirror.com/redent/-/redent-3.0.0.tgz" @@ -7241,11 +7121,6 @@ safe-regex-test@^1.0.0: get-intrinsic "^1.1.3" is-regex "^1.1.4" -safe-stable-stringify@^2.3.1: - version "2.4.0" - resolved "https://registry.npmmirror.com/safe-stable-stringify/-/safe-stable-stringify-2.4.0.tgz" - integrity sha512-eehKHKpab6E741ud7ZIMcXhKcP6TSIezPkNZhy5U8xC6+VvrRdUA2tMgxGxaGl4cz7c2Ew5+mg5+wNB16KQqrA== - "safer-buffer@>= 2.1.2 < 3": version "2.1.2" resolved "https://registry.npmmirror.com/safer-buffer/-/safer-buffer-2.1.2.tgz" @@ -7413,13 +7288,6 @@ slice-ansi@^5.0.0: ansi-styles "^6.0.0" is-fullwidth-code-point "^4.0.0" -sonic-boom@^3.1.0: - version "3.2.0" - resolved "https://registry.npmmirror.com/sonic-boom/-/sonic-boom-3.2.0.tgz" - integrity sha512-SbbZ+Kqj/XIunvIAgUZRlqd6CGQYq71tRRbXR92Za8J/R3Yh4Av+TWENiSiEgnlwckYLyP0YZQWVfyNC0dzLaA== - dependencies: - atomic-sleep "^1.0.0" - sortablejs@^1.15.0: version "1.15.0" resolved "https://registry.npmmirror.com/sortablejs/-/sortablejs-1.15.0.tgz" @@ -7491,11 +7359,6 @@ split2@^3.0.0: dependencies: readable-stream "^3.0.0" -split2@^4.0.0: - version "4.1.0" - resolved "https://registry.npmmirror.com/split2/-/split2-4.1.0.tgz" - integrity sha512-VBiJxFkxiXRlUIeyMQi8s4hgvKCSjtknJv/LVYbrgALPwf5zSKmEwV9Lst25AkvMDnvxODugjdl6KZgwKM1WYQ== - split@^1.0.0: version "1.0.1" resolved "https://registry.npmmirror.com/split/-/split-1.0.1.tgz" @@ -7807,13 +7670,6 @@ text-table@^0.2.0: resolved "https://registry.npmmirror.com/text-table/-/text-table-0.2.0.tgz" integrity sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw== -thread-stream@^2.0.0: - version "2.2.0" - resolved "https://registry.npmmirror.com/thread-stream/-/thread-stream-2.2.0.tgz" - integrity sha512-rUkv4/fnb4rqy/gGy7VuqK6wE1+1DOCOWy4RMeaV69ZHMP11tQKZvZSip1yTgrKCMZzEMcCL/bKfHvSfDHx+iQ== - dependencies: - real-require "^0.2.0" - throat@^6.0.1: version "6.0.1" resolved "https://registry.npmmirror.com/throat/-/throat-6.0.1.tgz"