@@ -1696,6 +1696,117 @@ Update them to point to this script instead?`,
16961696 'Publishing to Custom Domain "api.example.com" was skipped, fix conflict and try again'
16971697 ) ;
16981698 } ) ;
1699+ it ( "should deploy domains passed via --domain flag as custom domains" , async ( ) => {
1700+ writeWranglerConfig ( { } ) ;
1701+ writeWorkerSource ( ) ;
1702+ mockSubDomainRequest ( ) ;
1703+ mockUpdateWorkerSubdomain ( { enabled : false } ) ;
1704+ mockUploadWorkerRequest ( { expectedType : "esm" } ) ;
1705+ mockCustomDomainsChangesetRequest ( { } ) ;
1706+ mockPublishCustomDomainsRequest ( {
1707+ publishFlags : {
1708+ override_scope : true ,
1709+ override_existing_origin : false ,
1710+ override_existing_dns_record : false ,
1711+ } ,
1712+ domains : [ { hostname : "api.example.com" } ] ,
1713+ } ) ;
1714+
1715+ await runWrangler ( "deploy ./index --domain api.example.com" ) ;
1716+ expect ( std . out ) . toContain ( "api.example.com (custom domain)" ) ;
1717+ } ) ;
1718+
1719+ it ( "should deploy multiple domains passed via --domain flags" , async ( ) => {
1720+ writeWranglerConfig ( { } ) ;
1721+ writeWorkerSource ( ) ;
1722+ mockSubDomainRequest ( ) ;
1723+ mockUpdateWorkerSubdomain ( { enabled : false } ) ;
1724+ mockUploadWorkerRequest ( { expectedType : "esm" } ) ;
1725+ mockCustomDomainsChangesetRequest ( { } ) ;
1726+ mockPublishCustomDomainsRequest ( {
1727+ publishFlags : {
1728+ override_scope : true ,
1729+ override_existing_origin : false ,
1730+ override_existing_dns_record : false ,
1731+ } ,
1732+ domains : [
1733+ { hostname : "api.example.com" } ,
1734+ { hostname : "app.example.com" } ,
1735+ ] ,
1736+ } ) ;
1737+
1738+ await runWrangler (
1739+ "deploy ./index --domain api.example.com --domain app.example.com"
1740+ ) ;
1741+ expect ( std . out ) . toContain ( "api.example.com (custom domain)" ) ;
1742+ expect ( std . out ) . toContain ( "app.example.com (custom domain)" ) ;
1743+ } ) ;
1744+
1745+ it ( "should combine --domain flags with existing routes configuration" , async ( ) => {
1746+ writeWranglerConfig ( {
1747+ routes : [ "example.com/api/*" ] ,
1748+ } ) ;
1749+ writeWorkerSource ( ) ;
1750+ mockSubDomainRequest ( ) ;
1751+ mockUpdateWorkerSubdomain ( { enabled : false } ) ;
1752+ mockUploadWorkerRequest ( { expectedType : "esm" } ) ;
1753+ mockCustomDomainsChangesetRequest ( { } ) ;
1754+ mockPublishCustomDomainsRequest ( {
1755+ publishFlags : {
1756+ override_scope : true ,
1757+ override_existing_origin : false ,
1758+ override_existing_dns_record : false ,
1759+ } ,
1760+ domains : [ { hostname : "api.example.com" } ] ,
1761+ } ) ;
1762+ // Mock the regular route deployment for the configured route
1763+ msw . use (
1764+ http . put (
1765+ "*/accounts/:accountId/workers/scripts/:scriptName/routes" ,
1766+ ( ) => {
1767+ return HttpResponse . json (
1768+ {
1769+ success : true ,
1770+ errors : [ ] ,
1771+ messages : [ ] ,
1772+ result : [ "example.com/api/*" ] ,
1773+ } ,
1774+ { status : 200 }
1775+ ) ;
1776+ } ,
1777+ { once : true }
1778+ )
1779+ ) ;
1780+
1781+ await runWrangler ( "deploy ./index --domain api.example.com" ) ;
1782+ expect ( std . out ) . toContain ( "example.com/api/*" ) ;
1783+ expect ( std . out ) . toContain ( "api.example.com (custom domain)" ) ;
1784+ } ) ;
1785+
1786+ it ( "should validate domain flags and reject invalid domains with wildcards" , async ( ) => {
1787+ writeWranglerConfig ( { } ) ;
1788+ writeWorkerSource ( ) ;
1789+
1790+ await expect ( runWrangler ( "deploy ./index --domain *.example.com" ) )
1791+ . rejects . toThrowErrorMatchingInlineSnapshot ( `
1792+ [Error: Invalid Routes:
1793+ *.example.com:
1794+ Wildcard operators (*) are not allowed in Custom Domains]
1795+ ` ) ;
1796+ } ) ;
1797+
1798+ it ( "should validate domain flags and reject invalid domains with paths" , async ( ) => {
1799+ writeWranglerConfig ( { } ) ;
1800+ writeWorkerSource ( ) ;
1801+
1802+ await expect (
1803+ runWrangler ( "deploy ./index --domain api.example.com/path" )
1804+ ) . rejects . toThrowErrorMatchingInlineSnapshot ( `
1805+ [Error: Invalid Routes:
1806+ api.example.com/path:
1807+ Paths are not allowed in Custom Domains]
1808+ ` ) ;
1809+ } ) ;
16991810 } ) ;
17001811
17011812 describe ( "deploy asset routes" , ( ) => {
0 commit comments