-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
60 lines (58 loc) · 2.2 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { vitePluginApostropheDoctype } from './vite/vite-plugin-apostrophe-doctype.js';
import { vitePluginApostropheConfig } from './vite/vite-plugin-apostrophe-config.js';
export default function apostropheIntegration(options) {
return {
name: 'apostrophe-integration',
hooks: {
"astro:config:setup": ({ injectRoute, updateConfig, injectScript }) => {
if (!options.widgetsMapping || !options.templatesMapping) {
throw new Error('Missing required options')
}
updateConfig({
vite: {
plugins: [
vitePluginApostropheDoctype(
options.widgetsMapping,
options.templatesMapping
),
vitePluginApostropheConfig(
options.aposHost,
options.forwardHeaders,
options.viewTransitionWorkaround
),
],
},
});
const inject = [
'/apos-frontend/[...slug]',
'/api/v1/[...slug]',
'/[locale]/api/v1/[...slug]',
'/login',
'/[locale]/login',
'/uploads/[...slug]',
...(options.proxyRoutes || [])
];
for (const pattern of inject) {
// duplication of entrypoint needed for Astro 3.x support per
// https://docs.astro.build/en/guides/upgrade-to/v4/#renamed-entrypoint-integrations-api
injectRoute({
pattern,
entryPoint: '@apostrophecms/apostrophe-astro/endpoints/aposProxy.js',
entrypoint: '@apostrophecms/apostrophe-astro/endpoints/aposProxy.js'
});
}
// Different pattern from the rest
injectRoute({
pattern: '/[locale]/api/v1/@apostrophecms/area/render-widget',
entryPoint: '@apostrophecms/apostrophe-astro/endpoints/renderWidget.astro',
entrypoint: '@apostrophecms/apostrophe-astro/endpoints/renderWidget.astro'
});
injectRoute({
pattern: '/api/v1/@apostrophecms/area/render-widget',
entryPoint: '@apostrophecms/apostrophe-astro/endpoints/renderWidget.astro',
entrypoint: '@apostrophecms/apostrophe-astro/endpoints/renderWidget.astro'
});
}
}
};
};