@@ -37,8 +37,34 @@ class ResourceMapper {
37
37
}
38
38
}
39
39
40
- get rootPath ( ) {
41
- return this . _rootPath
40
+ // Returns the URL of the given HTTP request
41
+ getRequestUrl ( req ) {
42
+ const { hostname, pathname } = this . _parseUrl ( req )
43
+ return this . resolveUrl ( hostname , pathname )
44
+ }
45
+
46
+ // Returns the URL for the relative path on the pod
47
+ resolveUrl ( hostname , pathname = '' ) {
48
+ return ! this . _includeHost ? `${ this . _rootUrl } ${ pathname } `
49
+ : `${ this . _protocol } //${ hostname } ${ this . _port } ${ this . _rootUrl } ${ pathname } `
50
+ }
51
+
52
+ // Gets the base file path for the given hostname
53
+ getBaseFilePath ( hostname ) {
54
+ return ! this . _includeHost ? this . _rootPath : `${ this . _rootPath } /${ hostname } `
55
+ }
56
+
57
+ // Maps a given server file to a URL
58
+ async mapFileToUrl ( { path, hostname } ) {
59
+ // Remove the root path if specified
60
+ if ( path . startsWith ( this . _rootPath ) ) {
61
+ path = path . substring ( this . _rootPath . length )
62
+ }
63
+
64
+ // Determine the URL by chopping off everything after the dollar sign
65
+ const pathname = this . _removeDollarExtension ( path )
66
+ const url = `${ this . resolveUrl ( hostname ) } ${ encodeURI ( pathname . replace ( / \\ / g, '/' ) ) } `
67
+ return { url, contentType : this . _getContentTypeByExtension ( path ) }
42
68
}
43
69
44
70
// Maps the request for a given resource and representation format to a server file
@@ -100,32 +126,6 @@ class ResourceMapper {
100
126
}
101
127
}
102
128
103
- // Maps a given server file to a URL
104
- async mapFileToUrl ( { path, hostname } ) {
105
- // Determine the URL by chopping off everything after the dollar sign
106
- let pathname = this . _removeDollarExtension ( path . substring ( this . _rootPath . length ) )
107
- pathname = this . _replaceBackslashes ( pathname )
108
- const url = `${ this . resolveUrl ( hostname ) } ${ encodeURI ( pathname ) } `
109
- return { url, contentType : this . _getContentTypeByExtension ( path ) }
110
- }
111
-
112
- // Gets the base file path for the given hostname
113
- getBaseFilePath ( hostname ) {
114
- return ! this . _includeHost ? this . _rootPath : `${ this . _rootPath } /${ hostname } `
115
- }
116
-
117
- // Returns the URL for the given HTTP request
118
- getRequestUrl ( req ) {
119
- const { hostname, pathname } = this . _parseUrl ( req )
120
- return this . resolveUrl ( hostname , pathname )
121
- }
122
-
123
- // Returns the URL for the relative path on the pod
124
- resolveUrl ( hostname , pathname = '' ) {
125
- return ! this . _includeHost ? `${ this . _rootUrl } ${ pathname } `
126
- : `${ this . _protocol } //${ hostname } ${ this . _port } ${ this . _rootUrl } ${ pathname } `
127
- }
128
-
129
129
// Determine the full file path corresponding to a URL
130
130
_getFilePath ( url ) {
131
131
const { pathname, hostname } = this . _parseUrl ( url )
@@ -168,10 +168,6 @@ class ResourceMapper {
168
168
const dollarPos = path . lastIndexOf ( '$' )
169
169
return dollarPos < 0 ? path : path . substr ( 0 , dollarPos )
170
170
}
171
-
172
- _replaceBackslashes ( path ) {
173
- return path . replace ( / \\ / g, '/' )
174
- }
175
171
}
176
172
177
173
module . exports = ResourceMapper
0 commit comments