How to use @magento/upward-js - 9 common examples

To help you get started, we’ve selected a few @magento/upward-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / pwa-buildpack / lib / WebpackTools / plugins / UpwardDevServerPlugin.js View on Github external
async createMiddleware() {
        // The compiler is necessary to build the fallback filesystem
        // so UPWARd can use Webpack-generated assets in dev mode.
        const compiler = await this.getCompiler();

        // Standard filesystem-and-fetch IO.
        const defaultIO = upward.IOAdapter.default(this.upwardPath);

        // Use Webpack's in-memory file system for UPWARD file retrieval during
        // development. Allows for hot reloading of server-side configuration.

        const io = {
            async readFile(filepath, enc = 'utf8') {
                // If a version of the file is output by Webpack into the output folder, prefer that one.
                const outputBasedPath = path.resolve(
                    compiler.options.output.path,
                    path.relative(compiler.options.context, filepath)
                );
                // Most likely scenario: UPWARD needs an output asset.
                debug(
                    'compiler.outputFileSystem readFile %s %s',
                    outputBasedPath,
                    enc
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / pwa-buildpack / lib / WebpackTools / plugins / UpwardDevServerPlugin.js View on Github external
async networkFetch(path, options) {
                debug('networkFetch %s, %o', path, options);
                const { protocol } = new url.URL(path);
                if (protocol === 'https:') {
                    return fetch(
                        path,
                        Object.assign({ agent: httpsAgent }, options)
                    );
                }
                return fetch(path, options);
                // Use the https.Agent to allow self-signed certificates.
            }
        };

        this.middleware = await upward.middleware(
            this.upwardPath,
            this.env,
            io
        );
    }
    async getCompiler() {
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / pwa-buildpack / lib / WebpackTools / plugins / __tests__ / UpwardDevServerPlugin.spec.js View on Github external
upward.middleware.mockResolvedValueOnce(upwardHandler);

    const noRequestsWaiting = new UpwardDevServerPlugin({}, process.env);
    noRequestsWaiting.apply(compiler);
    expect(noRequestsWaiting.compiler).toBe(compiler);

    const hasRequestsWaiting = new UpwardDevServerPlugin(
        devServer,
        process.env,
        'path/to/upward'
    );
    devServer.after(app);
    const handler = app.use.mock.calls[0][0];

    handler(req, res, next);
    expect(upward.IOAdapter.default).not.toHaveBeenCalled();
    expect(upward.middleware).not.toHaveBeenCalled();
    expect(hasRequestsWaiting.middlewarePromise).toBeInstanceOf(Promise);

    hasRequestsWaiting.apply(compiler);
    await hasRequestsWaiting.middlewarePromise;

    expect(upward.IOAdapter.default).toHaveBeenCalledWith('path/to/upward');
    expect(upward.middleware).toHaveBeenCalledWith(
        'path/to/upward',
        process.env,
        expect.objectContaining({
            readFile: expect.any(Function),
            networkFetch: expect.any(Function)
        })
    );
    expect(upwardHandler).toHaveBeenCalledWith(req, res, next);
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / pwa-buildpack / lib / WebpackTools / plugins / __tests__ / UpwardDevServerPlugin.spec.js View on Github external
devServer,
        process.env,
        'path/to/upward'
    );
    devServer.after(app);
    const handler = app.use.mock.calls[0][0];

    handler(req, res, next);
    expect(upward.IOAdapter.default).not.toHaveBeenCalled();
    expect(upward.middleware).not.toHaveBeenCalled();
    expect(hasRequestsWaiting.middlewarePromise).toBeInstanceOf(Promise);

    hasRequestsWaiting.apply(compiler);
    await hasRequestsWaiting.middlewarePromise;

    expect(upward.IOAdapter.default).toHaveBeenCalledWith('path/to/upward');
    expect(upward.middleware).toHaveBeenCalledWith(
        'path/to/upward',
        process.env,
        expect.objectContaining({
            readFile: expect.any(Function),
            networkFetch: expect.any(Function)
        })
    );
    expect(upwardHandler).toHaveBeenCalledWith(req, res, next);
});
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-concept / server.js View on Github external
dir: __dirname,
                    interactive: false
                })
            );
            upwardServerOptions.host = hostname;
            upwardServerOptions.https = ssl;
            upwardServerOptions.port = envPort || ports.staging || 0;
        } catch (e) {
            console.log(
                'Could not configure or access custom host. Using loopback...',
                e.message
            );
        }
    }
    console.log('Launching UPWARD server\n');
    await createUpwardServer(upwardServerOptions);
    console.log('\nUPWARD server running.');
}
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-concept / server-lambda.js View on Github external
async function serve() {
    const config = loadEnvironment(__dirname);
    const upwardServerOptions = Object.assign(
        {},
        config.section('upwardJs'),
        config.section('stagingServer'),
        {
            env: process.env,
            before: app => {
                app.use(bestPractices());
            }
        }
    );

    const server = await createUpwardServer(upwardServerOptions);
    return server;
}
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / venia-concept / server.js View on Github external
before(app) {
                addImgOptMiddleware(
                    app,
                    Object.assign(
                        config.section('magento'),
                        config.section('imageService')
                    )
                );
                app.use(bestPractices());
            }
        }
github Jordaneisenburger / fallback-studio / src / pwa-studio / packages / pwa-buildpack / lib / WebpackTools / plugins / UpwardDevServerPlugin.js View on Github external
devServer.before = (app, ...rest) => {
            app.use(upward.bestPractices());
            if (oldBefore) oldBefore(app, ...rest);
        };
        const oldAfter = devServer.after;

@magento/upward-js

Implementation of the UPWARD spec as a NodeJS server

OSL-3.0
Latest version published 6 months ago

Package Health Score

81 / 100
Full package analysis