Repository: spaship/spaship (ts)

Issue:
Add root path spa support to deploy API
We need to add root path spa support to the deployment API by implementing the following rule:

When a spa is deployed via the API with path=/
Then the API will deploy this spa under a special keyword directory name called "ROOTSPA"

The router will know to route root path spas requests to this directory. via #349 

Pull request:
feat(common): add specific ROOTSPA case
<!--
Follow the steps to create the PR:

Subject: "feat/fix/docs(#issue_id): <PR Subject>"
Assignees: "Developers"
Projects: ""
-->

## Closes / Fixes / Resolves
Fix #350 
<!-- Comman separated list of GitHub Issue ID(s) -->

## Explain the feature/fix

<!-- Provide a clear explaination of the feature/fix implemented -->

## Does this PR introduce a breaking change

<!-- Yes/No -->

<!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications here. -->

## Screenshot(s)

<!-- If applicable, add screenshots to help explain your problem. -->

<details>
<summary>View Screenshots</summary>

<!-- Add your screenshot(s) below this line -->

</details>

### Ready-for-merge Checklist

- [ ] Expected files: all files in this pull request are related to one feature request or issue (no stragglers)?
- [ ] Does the change have appropriate unit tests?
- [ ] Did tests pass?
- [ ] Did you update or add any necessary documentation (README.md, WHY.md, etc.)?
- [ ] Was this feature demo'd and the design review approved?


Patch:
diff --git a/packages/common/lib/flatpath/index.js b/packages/common/lib/flatpath/index.js
index ac2082f1..95763bc4 100644
--- a/packages/common/lib/flatpath/index.js
+++ b/packages/common/lib/flatpath/index.js
@@ -1,4 +1,11 @@
+const rootSPAPath = "ROOTSPA";
+
 function toDir(urlPath) {
+  // Specific for root path
+  // #329 #350
+  if (urlPath === "/") {
+    return rootSPAPath;
+  }
   return urlPath
     .replace(/^\//, "") // Trim off leading /
     .replace(/_/g, "UNDRSCR") // Escape underscores with UNDRSCR token
@@ -6,6 +13,11 @@ function toDir(urlPath) {
 }
 
 function toUrl(flatDir) {
+  // Specific for root path
+  // #329 #350
+  if (flatDir === rootSPAPath) {
+    return "/";
+  }
   return (
     "/" +
     flatDir


Test patch:
diff --git a/packages/common/lib/flatpath/index.test.js b/packages/common/lib/flatpath/index.test.js
index b98f5bce..6e4399c1 100644
--- a/packages/common/lib/flatpath/index.test.js
+++ b/packages/common/lib/flatpath/index.test.js
@@ -30,6 +30,10 @@ describe("common/flatpath", () => {
       expect(flatpath.toDir("/_foo_bar/_baz")).toEqual("UNDRSCRfooUNDRSCRbar_UNDRSCRbaz");
       expect(flatpath.toDir("/foo_bar_ba/z_")).toEqual("fooUNDRSCRbarUNDRSCRba_zUNDRSCR");
     });
+
+    test("should handle root path", () => {
+      expect(flatpath.toDir("/")).toEqual("ROOTSPA");
+    });
   });
   describe("map from dir to URL", () => {
     // test("should have a special mapping for root path", () => {
@@ -60,5 +64,9 @@ describe("common/flatpath", () => {
       expect(flatpath.toUrl("UNDRSCRfooUNDRSCRbar_UNDRSCRbaz")).toEqual("/_foo_bar/_baz");
       expect(flatpath.toUrl("fooUNDRSCRbarUNDRSCRba_zUNDRSCR")).toEqual("/foo_bar_ba/z_");
     });
+
+    test("should restore ROOTSPA dir", () => {
+      expect(flatpath.toUrl("ROOTSPA")).toEqual("/");
+    });
   });
 });