mirror of
https://github.com/withastro/astro.git
synced 2025-03-17 23:11:29 -05:00
Remove integration-specific code
This commit is contained in:
parent
8fabda7e00
commit
90a862fc94
4 changed files with 1 additions and 46 deletions
|
@ -3290,7 +3290,6 @@ declare global {
|
|||
server: vite.ViteDevServer;
|
||||
logger: AstroIntegrationLogger;
|
||||
toolbar: ReturnType<typeof getToolbarServerCommunicationHelpers>;
|
||||
refreshContent?: (options: RefreshContentOptions) => Promise<void>;
|
||||
}) => void | Promise<void>;
|
||||
'astro:server:start': (options: {
|
||||
address: AddressInfo;
|
||||
|
|
|
@ -31,8 +31,6 @@ export interface LoaderContext {
|
|||
/** When running in dev, this is a filesystem watcher that can be used to trigger updates */
|
||||
watcher?: FSWatcher;
|
||||
|
||||
/** If the loader has been triggered by an integration, this may optionally contain extra data set by that integration */
|
||||
refreshContextData?: Record<string, unknown>;
|
||||
entryTypes: Map<string, ContentEntryType>;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,11 +12,9 @@ import type {
|
|||
ContentEntryType,
|
||||
DataEntryType,
|
||||
HookParameters,
|
||||
RefreshContentOptions,
|
||||
RouteData,
|
||||
RouteOptions,
|
||||
} from '../@types/astro.js';
|
||||
import { globalContentLayer } from '../content/content-layer.js';
|
||||
import astroIntegrationActionsRouteHandler from '../actions/integration.js';
|
||||
import { isActionsFilePresent } from '../actions/utils.js';
|
||||
import type { SerializedSSRManifest } from '../core/app/types.js';
|
||||
|
@ -375,14 +373,6 @@ export async function runHookServerSetup({
|
|||
server: ViteDevServer;
|
||||
logger: Logger;
|
||||
}) {
|
||||
let refreshContent: undefined | ((options: RefreshContentOptions) => Promise<void>);
|
||||
if (config.experimental?.contentLayer) {
|
||||
refreshContent = async (options: RefreshContentOptions) => {
|
||||
const contentLayer = await globalContentLayer.get();
|
||||
await contentLayer?.sync(options);
|
||||
};
|
||||
}
|
||||
|
||||
for (const integration of config.integrations) {
|
||||
if (integration?.hooks?.['astro:server:setup']) {
|
||||
await withTakingALongTimeMsg({
|
||||
|
@ -392,7 +382,6 @@ export async function runHookServerSetup({
|
|||
server,
|
||||
logger: getLogger(integration, logger),
|
||||
toolbar: getToolbarServerCommunicationHelpers(server),
|
||||
refreshContent,
|
||||
}),
|
||||
logger,
|
||||
});
|
||||
|
|
|
@ -3,38 +3,7 @@ import { defineConfig } from 'astro/config';
|
|||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
export default defineConfig({
|
||||
integrations: [mdx(), {
|
||||
name: '@astrojs/my-integration',
|
||||
hooks: {
|
||||
'astro:server:setup': async ({ server, refreshContent }) => {
|
||||
server.middlewares.use('/_refresh', async (req, res) => {
|
||||
if(req.method !== 'POST') {
|
||||
res.statusCode = 405
|
||||
res.end('Method Not Allowed');
|
||||
return
|
||||
}
|
||||
let body = '';
|
||||
req.on('data', chunk => {
|
||||
body += chunk.toString();
|
||||
});
|
||||
req.on('end', async () => {
|
||||
try {
|
||||
const webhookBody = JSON.parse(body);
|
||||
await refreshContent({
|
||||
context: { webhookBody },
|
||||
loaders: ['increment-loader']
|
||||
});
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ message: 'Content refreshed successfully' }));
|
||||
} catch (error) {
|
||||
res.writeHead(500, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({ error: 'Failed to refresh content' }));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}],
|
||||
integrations: [mdx()],
|
||||
vite: {
|
||||
resolve: {
|
||||
alias: {
|
||||
|
|
Loading…
Add table
Reference in a new issue