UNPKG

1.51 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4exports.__esModule = true;
5exports.onCreateDevServer = onCreateDevServer;
6var _path = _interopRequireDefault(require("path"));
7var _utils = require("@builder.io/partytown/utils");
8var _proxy = require("./proxy");
9/**
10 * Copy Partytown library files to public.
11 * @see {@link https://partytown.builder.io/copy-library-files}
12 */
13exports.onPreBootstrap = async ({
14 store
15}) => {
16 const {
17 program
18 } = store.getState();
19 await (0, _utils.copyLibFiles)(_path.default.join(program.directory, `public`, `~partytown`));
20};
21
22/**
23 * Implement reverse proxy so scripts can fetch in web workers without CORS errors.
24 * @see {@link https://partytown.builder.io/proxying-requests}
25 */
26exports.createPages = ({
27 actions,
28 store
29}) => {
30 const {
31 createRedirect
32 } = actions;
33 const {
34 config = {}
35 } = store.getState();
36 const {
37 partytownProxiedURLs = []
38 } = config;
39 for (const host of partytownProxiedURLs) {
40 const encodedURL = encodeURIComponent(host);
41 createRedirect({
42 fromPath: `${_proxy.thirdPartyProxyPath}?url=${encodedURL}`,
43 toPath: host,
44 statusCode: 200
45 });
46 }
47};
48async function onCreateDevServer({
49 app,
50 store
51}) {
52 const {
53 config
54 } = store.getState();
55 const {
56 partytownProxiedURLs = []
57 } = config || {};
58 app.use(_proxy.thirdPartyProxyPath, (0, _proxy.partytownProxy)(partytownProxiedURLs));
59}
60//# sourceMappingURL=gatsby-node.js.map
\No newline at end of file