mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
fix: code split correctly
This commit is contained in:
1 parent
f48c5d246d
commit
9bf1554c30
3 files changed
+10
-11
No files matched your search
@@ -4,7 +4,7 @@ import { CatalogItemAccessor } from './catalogItemAccessor';
|
||||
import { MetadataAccessor } from './metadata';
|
||||
|
||||
export class SocketMetadataAccessor extends MetadataAccessor {
|
||||
private items: Record<string, CatalogItem> = {};
|
||||
items: Record<string, CatalogItem> = {};
|
||||
|
||||
constructor(metadata: Metadata) {
|
||||
super();
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import type { MetadataAccessor } from 'packages/core/src';
|
||||
import { remoteMetadata } from './metadata.remote';
|
||||
import { socketMetadata } from './metadata.socket';
|
||||
|
||||
let accessor: MetadataAccessor;
|
||||
|
||||
if (import.meta.env.SSR) {
|
||||
accessor = socketMetadata;
|
||||
accessor = await import('./metadata.socket').then((m) => m.socketMetadata);
|
||||
} else {
|
||||
accessor = remoteMetadata;
|
||||
accessor = await import('./metadata.remote').then((m) => m.remoteMetadata);
|
||||
}
|
||||
|
||||
export const metadata = accessor;
|
||||
@@ -1,18 +1,19 @@
|
||||
import type { APIRoute, GetStaticPaths, GetStaticPathsItem } from 'astro';
|
||||
import { catalog } from 'packages/website-ue/src/core/blitz/metadata';
|
||||
import { socketMetadata } from 'packages/website-ue/src/core/blitz/metadata.socket';
|
||||
|
||||
export const getStaticPaths: GetStaticPaths = () => {
|
||||
const paths: GetStaticPathsItem[] = [];
|
||||
|
||||
for (const item in catalog.items) {
|
||||
for (const item in socketMetadata.items) {
|
||||
paths.push({ params: { item } });
|
||||
}
|
||||
|
||||
return paths;
|
||||
};
|
||||
|
||||
export const GET: APIRoute<{}, { item: string }> = ({ params }) => {
|
||||
return new Response(catalog.get(params.item).encode(), {
|
||||
headers: { 'Content-Type': 'application/octet-stream' },
|
||||
});
|
||||
export const GET: APIRoute<{}, { item: string }> = async ({ params }) => {
|
||||
return new Response(
|
||||
await socketMetadata.get(params.item).then((item) => item.encode()),
|
||||
{ headers: { 'Content-Type': 'application/octet-stream' } },
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user