@@ -1692,6 +1692,161 @@ Update them to point to this script instead?`,
16921692 'Publishing to Custom Domain "api.example.com" was skipped, fix conflict and try again'
16931693 ) ;
16941694 } ) ;
1695+ it ( "should deploy domains passed via --domain flag as custom domains" , async ( ) => {
1696+ writeWranglerConfig ( { } ) ;
1697+ writeWorkerSource ( ) ;
1698+ mockSubDomainRequest ( ) ;
1699+ mockUpdateWorkerSubdomain ( { enabled : false } ) ;
1700+ mockUploadWorkerRequest ( { expectedType : "esm" } ) ;
1701+ mockCustomDomainsChangesetRequest ( { } ) ;
1702+ mockPublishCustomDomainsRequest ( {
1703+ publishFlags : {
1704+ override_scope : true ,
1705+ override_existing_origin : false ,
1706+ override_existing_dns_record : false ,
1707+ } ,
1708+ domains : [ { hostname : "api.example.com" } ] ,
1709+ } ) ;
1710+
1711+ await runWrangler ( "deploy ./index --domain api.example.com" ) ;
1712+ expect ( std . out ) . toContain ( "api.example.com (custom domain)" ) ;
1713+ } ) ;
1714+
1715+ it ( "should deploy multiple domains passed via --domain flags" , async ( ) => {
1716+ writeWranglerConfig ( { } ) ;
1717+ writeWorkerSource ( ) ;
1718+ mockSubDomainRequest ( ) ;
1719+ mockUpdateWorkerSubdomain ( { enabled : false } ) ;
1720+ mockUploadWorkerRequest ( { expectedType : "esm" } ) ;
1721+ mockCustomDomainsChangesetRequest ( { } ) ;
1722+ mockPublishCustomDomainsRequest ( {
1723+ publishFlags : {
1724+ override_scope : true ,
1725+ override_existing_origin : false ,
1726+ override_existing_dns_record : false ,
1727+ } ,
1728+ domains : [
1729+ { hostname : "api.example.com" } ,
1730+ { hostname : "app.example.com" } ,
1731+ ] ,
1732+ } ) ;
1733+
1734+ await runWrangler (
1735+ "deploy ./index --domain api.example.com --domain app.example.com"
1736+ ) ;
1737+ expect ( std . out ) . toContain ( "api.example.com (custom domain)" ) ;
1738+ expect ( std . out ) . toContain ( "app.example.com (custom domain)" ) ;
1739+ } ) ;
1740+
1741+ it ( "should deploy --domain flags alongside routes (from config when no CLI routes)" , async ( ) => {
1742+ writeWranglerConfig ( {
1743+ routes : [ "example.com/api/*" ] ,
1744+ } ) ;
1745+ writeWorkerSource ( ) ;
1746+ mockSubDomainRequest ( ) ;
1747+ mockUpdateWorkerSubdomain ( { enabled : false } ) ;
1748+ mockUploadWorkerRequest ( { expectedType : "esm" } ) ;
1749+ mockCustomDomainsChangesetRequest ( { } ) ;
1750+ mockPublishCustomDomainsRequest ( {
1751+ publishFlags : {
1752+ override_scope : true ,
1753+ override_existing_origin : false ,
1754+ override_existing_dns_record : false ,
1755+ } ,
1756+ domains : [ { hostname : "api.example.com" } ] ,
1757+ } ) ;
1758+ // Mock the regular route deployment for the configured route
1759+ msw . use (
1760+ http . put (
1761+ "*/accounts/:accountId/workers/scripts/:scriptName/routes" ,
1762+ ( ) => {
1763+ return HttpResponse . json (
1764+ {
1765+ success : true ,
1766+ errors : [ ] ,
1767+ messages : [ ] ,
1768+ result : [ "example.com/api/*" ] ,
1769+ } ,
1770+ { status : 200 }
1771+ ) ;
1772+ } ,
1773+ { once : true }
1774+ )
1775+ ) ;
1776+
1777+ await runWrangler ( "deploy ./index --domain api.example.com" ) ;
1778+ expect ( std . out ) . toContain ( "example.com/api/*" ) ;
1779+ expect ( std . out ) . toContain ( "api.example.com (custom domain)" ) ;
1780+ } ) ;
1781+
1782+ it ( "should validate domain flags and reject invalid domains with wildcards" , async ( ) => {
1783+ writeWranglerConfig ( { } ) ;
1784+ writeWorkerSource ( ) ;
1785+
1786+ await expect ( runWrangler ( "deploy ./index --domain *.example.com" ) )
1787+ . rejects . toThrowErrorMatchingInlineSnapshot ( `
1788+ [Error: Invalid Routes:
1789+ *.example.com:
1790+ Wildcard operators (*) are not allowed in Custom Domains]
1791+ ` ) ;
1792+ } ) ;
1793+
1794+ it ( "should validate domain flags and reject invalid domains with paths" , async ( ) => {
1795+ writeWranglerConfig ( { } ) ;
1796+ writeWorkerSource ( ) ;
1797+
1798+ await expect (
1799+ runWrangler ( "deploy ./index --domain api.example.com/path" )
1800+ ) . rejects . toThrowErrorMatchingInlineSnapshot ( `
1801+ [Error: Invalid Routes:
1802+ api.example.com/path:
1803+ Paths are not allowed in Custom Domains]
1804+ ` ) ;
1805+ } ) ;
1806+
1807+ it ( "should handle both --route and --domain flags together" , async ( ) => {
1808+ writeWranglerConfig ( {
1809+ routes : [ "config.com/api/*" ] ,
1810+ } ) ;
1811+ writeWorkerSource ( ) ;
1812+ mockSubDomainRequest ( ) ;
1813+ mockUpdateWorkerSubdomain ( { enabled : false } ) ;
1814+ mockUploadWorkerRequest ( { expectedType : "esm" } ) ;
1815+ mockCustomDomainsChangesetRequest ( { } ) ;
1816+ mockPublishCustomDomainsRequest ( {
1817+ publishFlags : {
1818+ override_scope : true ,
1819+ override_existing_origin : false ,
1820+ override_existing_dns_record : false ,
1821+ } ,
1822+ domains : [ { hostname : "api.example.com" } ] ,
1823+ } ) ;
1824+ // Mock the regular route deployment for the CLI route (should override config)
1825+ msw . use (
1826+ http . put (
1827+ "*/accounts/:accountId/workers/scripts/:scriptName/routes" ,
1828+ ( ) => {
1829+ return HttpResponse . json (
1830+ {
1831+ success : true ,
1832+ errors : [ ] ,
1833+ messages : [ ] ,
1834+ result : [ "cli.com/override/*" ] ,
1835+ } ,
1836+ { status : 200 }
1837+ ) ;
1838+ } ,
1839+ { once : true }
1840+ )
1841+ ) ;
1842+
1843+ await runWrangler (
1844+ "deploy ./index --route cli.com/override/* --domain api.example.com"
1845+ ) ;
1846+ expect ( std . out ) . toContain ( "cli.com/override/*" ) ;
1847+ expect ( std . out ) . toContain ( "api.example.com (custom domain)" ) ;
1848+ expect ( std . out ) . not . toContain ( "config.com/api/*" ) ;
1849+ } ) ;
16951850 } ) ;
16961851
16971852 describe ( "deploy asset routes" , ( ) => {
0 commit comments