braidfs 0.0.14 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +11 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -85,7 +85,7 @@ const server = http.createServer(async (req, res) => {
85
85
  proxy_url(url)
86
86
 
87
87
  // Now serve the collaborative text!
88
- braid_text.serve(req, res, { key: url })
88
+ braid_text.serve(req, res, { key: normalize_url(url) })
89
89
  });
90
90
 
91
91
  server.listen(port, () => {
@@ -95,6 +95,10 @@ server.listen(port, () => {
95
95
 
96
96
  ////////////////////////////////
97
97
 
98
+ function normalize_url(url) {
99
+ return url.replace(/(\/index|\/)+$/, '')
100
+ }
101
+
98
102
  async function proxy_url(url) {
99
103
  let chain = proxy_url.chain || (proxy_url.chain = Promise.resolve())
100
104
 
@@ -115,7 +119,7 @@ async function proxy_url(url) {
115
119
  await require("fs").promises.mkdir(path, { recursive: true })
116
120
 
117
121
  while (await is_dir(partial))
118
- partial = require("path").join(partial, 'index.html')
122
+ partial = require("path").join(partial, 'index')
119
123
 
120
124
  await require("fs").promises.writeFile(partial, save)
121
125
  break
@@ -125,8 +129,8 @@ async function proxy_url(url) {
125
129
  }))
126
130
  }
127
131
 
128
- // normalize url by removing any trailing /index.html/index.html/
129
- let normalized_url = url.replace(/(\/index\.html|\/)+$/, '')
132
+ // normalize url by removing any trailing /index/index/
133
+ let normalized_url = normalize_url(url)
130
134
  let wasnt_normal = normalized_url != url
131
135
  url = normalized_url
132
136
 
@@ -139,7 +143,7 @@ async function proxy_url(url) {
139
143
  let path = url.replace(/^https?:\/\//, '')
140
144
  let fullpath = require("path").join(proxy_base, path)
141
145
 
142
- // if we're accessing /blah/index.html, it will be normalized to /blah,
146
+ // if we're accessing /blah/index, it will be normalized to /blah,
143
147
  // but we still want to create a directory out of blah in this case
144
148
  if (wasnt_normal && !(await is_dir(fullpath))) await ensure_path(fullpath)
145
149
 
@@ -149,7 +153,7 @@ async function proxy_url(url) {
149
153
 
150
154
  async function get_fullpath() {
151
155
  let p = fullpath
152
- while (await is_dir(p)) p = require("path").join(p, 'index.html')
156
+ while (await is_dir(p)) p = require("path").join(p, 'index')
153
157
  return p
154
158
  }
155
159
 
@@ -275,7 +279,7 @@ async function proxy_url(url) {
275
279
  path = require('path').relative(proxy_base, path)
276
280
  console.log(`path changed: ${path}`)
277
281
 
278
- path = path.replace(/(\/index\.html|\/)+$/, '')
282
+ path = normalize_url(path)
279
283
  // console.log(`normalized path: ${path}`)
280
284
 
281
285
  proxy_url.path_to_func[path]()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braidfs",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "description": "braid technology synchronizing files and webpages",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braidfs",