UNPKG

@adpt/cloud

Version:
100 lines 3.49 kB
"use strict"; /* * Copyright 2019 Unbounded Systems, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const core_1 = tslib_1.__importStar(require("@adpt/core")); const http_1 = require("../http"); const LocalNodeImage_1 = require("./LocalNodeImage"); const defaultBuildOptions = { imageName: "react-app", packageManager: "yarn", runNpmScripts: "build", }; const defaultHttpOptions = { scope: "cluster-internal", }; const defaultOptions = { buildOptions: {}, httpOptions: {}, }; /** * A partially abstract component that builds * {@link https://reactjs.org | ReactJS} source code and serves the resulting * files via an {@link http.HttpServer}. * * @remarks * To use this component, the `srcDir` prop must be the path to the root of * a ReactJS project, which contains a package.json file. The component will * build a Docker container image by: * * - starting with an official Node.js base image * * - copying `srcDir` into the container image * * - executing `yarn run build` * * It will then copy the resulting `build` directory into an {@link http.HttpServer} * component. * * Abstract components: * * This component uses the following abstract components (via * {@link http.HttpServer})which must be replaced via style sheet rules: * * - {@link Service} * * - {@link NetworkService} * * - {@link Container} * * The {@link NetworkService} and {@link Container} components are both * children of the {@link Service} component. * * Instance methods: * * - hostname(): string | undefined * * Returns the hostname of the NetworkService, once it is known. * * - port(): number | undefined * * Returns the port number of the NetworkService, once it is known. * * @public */ function ReactApp(props) { const bProps = props; const buildOptions = Object.assign({}, defaultBuildOptions, bProps.buildOptions); const [appImg, web] = [core_1.handle(), core_1.handle()]; core_1.useMethodFrom(web, "hostname"); core_1.useMethodFrom(web, "port"); const add = [ { type: "image", image: appImg, stage: "app", files: [{ src: "/app/build", dest: "/www/static" }] }, ...(bProps.httpOptions.add || []) ]; const httpOptions = Object.assign({}, defaultHttpOptions, bProps.httpOptions, { add }); return (core_1.default.createElement(core_1.Sequence, { key: bProps.key }, core_1.default.createElement(LocalNodeImage_1.LocalNodeImage, { key: bProps.key + "-img", handle: appImg, srcDir: bProps.srcDir, options: buildOptions }), core_1.default.createElement(http_1.HttpServer, Object.assign({ key: bProps.key, handle: web }, httpOptions)))); } exports.ReactApp = ReactApp; // TODO: The "as any" is a workaround for an api-extractor bug. See issue #185. ReactApp.defaultProps = defaultOptions; //# sourceMappingURL=ReactApp.js.map