Skip to content

Commit 006a0f5

Browse files
save file
1 parent 17d9757 commit 006a0f5

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

blog/25-07-24/http-server/ex/http-server-simple-example.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,28 +127,32 @@
127127
url = decodeURI(url);
128128
url = url.slice(1);
129129
resolve.df && console.log('url :',url);
130-
var p2 = path.resolve(docroot);
131-
resolve.df && console.log('p2 :',p2);
132-
var file = path.resolve(docroot,url);
133-
resolve.df && console.log('file :',file);
134-
var s = file.substring(0,p2.length);
135-
resolve.df && console.log('s :',s);
136-
var p1 = path.resolve(s);
137-
resolve.df && console.log('p1 :',p1);
138-
if(p1!==p2){
130+
var root = path.resolve(docroot);
131+
root += path.sep;
132+
resolve.df && console.log('root :',root);
133+
var abs = path.resolve(docroot,url);
134+
resolve.df && console.log('abs :',abs);
135+
136+
if(!abs.startsWith(root)){
139137
resolve.df && console.log('fail');
140138
return false;
141139
}
142140

143141
if(url.endsWith('/')){
144-
file += '/';
142+
abs += '/';
145143
}
146-
resolve.df && console.log('ok',file);
147-
return file;
144+
resolve.df && console.log('ok',abs);
145+
return abs;
148146

149147
}//resolve
150148

151149

150+
151+
/*
152+
if(!file.startsWith(p2)){
153+
}
154+
*/
155+
152156
//:
153157

154158

0 commit comments

Comments
 (0)