UNPKG

@shopify/cli-kit

Version:

A set of utilities, interfaces, and models that are common across all the platform features

28 lines 1.27 kB
import fs from 'node:fs'; import { assertCompatibleEnvironment } from './env.js'; export function createServer(projectName) { return { host: (options = {}) => host(projectName, options), url: (options = {}) => url(projectName, options), }; } function host(projectName, { nonstandardHostPrefix } = {}) { assertCompatibleEnvironment(); const services = fs.readdirSync('/run/ports2').filter((file) => file.endsWith(`--${projectName}`)); if (services.length === 0) { throw new Error(`DevServer for '${projectName}' not present in this spin environment`); } // Spin mostly doesn't do alternative hostname prefixing for core. if (projectName === 'shopify') { const prefix = nonstandardHostPrefix?.replace(/[-_]dev[-_]api$/, ''); return `${prefix}.${projectName}.${process.env.SPIN_FQDN}`; } const match = new RegExp(`^(.+)${projectName}$`).exec(services[0]); const organization = match ? match[1] : ''; const spinPrefix = organization === 'shopify--' ? '' : `${organization}`; return `${spinPrefix}${projectName}.${process.env.SPIN_FQDN}`; } function url(projectName, options = {}) { return `https://${host(projectName, options)}`; } //# sourceMappingURL=dev-server-spin.js.map