Skip to content

Commit

Permalink
refactor: use nginx & csr (#47)
Browse files Browse the repository at this point in the history
> close #46 

* 调整版本列表页同步说明
* 更新 build 配置
* 去除 /api/info 及 /api/spec 相关接口实现
  • Loading branch information
elrrrrrrr authored Oct 16, 2023
1 parent 79958e6 commit 4d23e39
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 14 deletions.
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ module.exports = {
httpAgentOptions: {
keepAlive: false,
},
output: 'export',
}
6 changes: 3 additions & 3 deletions src/components/SyncAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export default function SyncAlert({pkg, needSync}: SyncAlertProps) {
}

if (needSync === undefined) {
type = 'warning';
message = '查询源站版本信息失败';
type = 'info';
message = '目前暂不支持自动版本比对,需访问源站进行确认';
}

return (
Expand All @@ -52,7 +52,7 @@ export default function SyncAlert({pkg, needSync}: SyncAlertProps) {
showIcon
action={
<Space direction='vertical'>
{needSync && <Sync pkgName={pkg.name} />}
{<Sync pkgName={pkg.name} />}
{registry !== 'self' && (
<Button
size='small'
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/useManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, { useMemo } from "react";
import useSwr from 'swr';
import dayjs from "dayjs";

const REGISTRY = 'https://registry.npmmirror.com';

export interface NpmPackageVersion {
name: string;
version: string;
Expand Down Expand Up @@ -69,7 +71,7 @@ export function useVersionTags(manifest: PackageManifest) {

export function useInfo(pkgName: string | undefined) {
return useSwr(pkgName ? `info: ${pkgName}` : null, async () => {
const target = `/api/info?pkgName=${pkgName || ''}`;
const target = `${REGISTRY}/${pkgName}`;
const res = await fetch(target.toString());
if (res.status === 404) {
throw new Error(`Not Found ${pkgName}`);
Expand All @@ -88,7 +90,7 @@ export function useSpec(pkgName: string | undefined, spec: string | undefined, i
return pkgName && spec && !info?.versions?.[spec];
}, [pkgName, spec, info]);
return useSwr(needFetch ? `spec: ${pkgName}_${spec}` : null, async () => {
const target = `/api/spec?pkgName=${pkgName || ''}&spec=${spec || ''}`;
const target = `${REGISTRY}/${pkgName || ''}/${spec}`;
const res = await fetch(target.toString());
if (res.status === 404) {
throw new Error(`Not Found ${pkgName}`);
Expand Down
2 changes: 0 additions & 2 deletions src/pages/api/spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { PackageManifest } from "@/hooks/useManifest";
import { isEqual } from "lodash";
import { NextApiRequest, NextApiResponse } from "next";

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/package/[...slug]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default function PackagePage({
const { data, isLoading, error } = useInfo(pkgName);
const { data: specInfo } = useSpec(pkgName, routerVersion, data?.data);

const resData = data?.data;
const resData = data;
const specVersion = specInfo?.version;
const needSync = data?.needSync;

Expand Down
6 changes: 0 additions & 6 deletions src/pages/packages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import SizeContainer from '@/components/SizeContainer';
import { SearchItem, useCachedSearch } from '@/hooks/useSearch';
import { Col, Empty, Pagination, Row, Space } from 'antd';
import { PackageCard } from '@/components/PackageCard';
import { NextPageContext } from 'next';

const ThemeProvider = _ThemeProvider as any;

Expand Down Expand Up @@ -110,8 +109,3 @@ export default function Packages({page: initPage, q: initQ}: PageType) {
</ThemeProvider>
);
}

export async function getServerSideProps(context: NextPageContext) {
const { page = 1, q = ''} = context.query;
return { props: { page, q } };
}

0 comments on commit 4d23e39

Please sign in to comment.