import type { ExpandedSourcePath } from './ExpandedSourcePath.js'; /** * A route match can be a string path or an object with a path and domain. */ export type RouteMatch = string | { path: string; domain?: string; }; export interface SharedRouteOptions { /** * The URL path to match. Paths should usually start with a slash, e.g. `'/my-route'`. * You can also use wildcards (`*`), e.g. `'/my-route/*'` to match all paths starting with `'/my-route'`. * * See the [Express docs](https://expressjs.com/en/guide/routing.html#route-paths) for the full * supported routing syntax. * * If you need a route to match on a specific domain, you can pass an object (path, domain) in where * the domain is a string which can have wildcards (`*`). e.g. `'word.*'` will match `word.com`, `word.net`, etc. * * Use an array to handle multiple paths with the same route handler. */ match: RouteMatch | RouteMatch[]; } /** * A server-rendered route with optional shorthand `entry` info (as specified in `AppConfig`/`cloudpack.config.json`). * The route is rendered by a custom server script in Cloudpack. */ export interface ShorthandRenderedRoute extends SharedRouteOptions { /** * Path to a .js or .html file (relative to the app path) for rendering the route. * * If a .js file, it must export a default function implementing `RenderFunction` from `@ms-cloudpack/common-types`. * @deprecated Use `serverEntry` instead. (Please talk to the team if you have a scenario where * bundling the script causes a problem.) */ renderScript?: string; /** * The key in the exports map which represents the entry point app script for this route. * @deprecated Use `entry` instead. */ exportEntry?: string; /** * Additional source file path(s) to bundle and include in the HTML. * This **overwrites** any original exports map for the package. * * Usually this should be an actual source path, though it could also be an exports map key if necessary. */ entry?: string | string[]; /** * Path to a TS, JS, or HTML file (relative to the app path) for rendering the route on the server. * (Also supports export map keys.) If a JS or TS file, it will be bundled before rendering. * * If JS or TS, it must export a default function implementing `RenderRouteFunction` defined in * `@ms-cloudpack/app-server`. */ serverEntry?: string; } /** * A server-rendered route with full `entry` info (used in the processed `CloudpackConfig`). * The route is rendered by a custom server script in Cloudpack. */ export type RenderedRoute = Omit & { /** * The source entry or entries to be included on the page for this route. */ entry?: ExpandedSourcePath[]; /** * Path to a TS, JS, or HTML file (relative to the app path) for rendering the route on the server. * If a JS or TS file, it will be bundled before rendering. * * If JS or TS, it must export a default function implementing `RenderRouteFunction` defined in * `@ms-cloudpack/app-server`. */ serverEntry?: ExpandedSourcePath; }; /** * A route with a staticPath property serves static files from the specified path. */ export interface StaticRoute extends SharedRouteOptions { /** * The path relative to the app root to static assets. */ staticPath: string; } /** * A route that serves a bootstrap script. */ export interface ShorthandBootstrapRoute extends SharedRouteOptions, Pick { type: 'bootstrap'; /** * Defer execution of scripts until the entry has loaded (default: false). */ deferScripts?: boolean; } /** * A route that serves a bootstrap script. */ export interface BootstrapRoute extends Omit, Pick { } /** * A route that redirects to another url. */ export interface RedirectRoute extends SharedRouteOptions { /** * The url to redirect to. */ redirectTo: string; } /** * A route that proxies requests to another server. * This is handled by https://github.com/chimurai/http-proxy-middleware. */ export interface ProxyRoute extends SharedRouteOptions { /** * The target host to proxy to. (protocol + host). */ proxyTo: string; /** * For virtual hosted sites. */ changeOrigin?: boolean; /** * Rewrite target's url path. Object-keys will be used as RegExp to match paths. */ pathRewrite?: Record; } /** * Route as specified in `AppConfig` (`cloudpack.config.json`). */ export type ShorthandRoute = ShorthandRenderedRoute | ShorthandBootstrapRoute | StaticRoute | RedirectRoute | ProxyRoute; /** * Processed route as used in the processed `CloudpackConfig`. */ export type Route = RenderedRoute | BootstrapRoute | StaticRoute | RedirectRoute | ProxyRoute; /** * Type guard to check if a route is a static route. */ export declare function isStaticRoute(route: Route | ShorthandRoute): route is StaticRoute; /** * Type guard to check if a route is a bootstrap route. */ export declare function isBootstrapRoute(route: Route): route is BootstrapRoute; /** * Type guard to check if a route is a shorthand bootstrap route. */ export declare function isShorthandBootstrapRoute(route: ShorthandRoute): route is ShorthandBootstrapRoute; export declare function isRenderedRoute(route: Route): route is RenderedRoute; /** * Type guard to check if a route is a shorthand rendered route. */ export declare function isShorthandRenderedRoute(route: ShorthandRoute): route is ShorthandRenderedRoute; /** * Type guard to check if a route is a redirect route. */ export declare function isRedirectRoute(route: Route | ShorthandRoute): route is RedirectRoute; /** * Type guard to check if a route is a proxy route. */ export declare function isProxyRoute(route: Route | ShorthandRoute): route is ProxyRoute; //# sourceMappingURL=Route.d.ts.map