@@ -64,10 +64,10 @@ class NotionProxy {
64
64
let url ;
65
65
try {
66
66
url = utility . generateNotionUrl ( req , res , this . PERMA_TO_PAGE , this . SLUG_TO_PAGE ) ;
67
- //console.log('PROXY_TO ' + url)
67
+ // console.log('[DEBUG] PROXY_TO ' + url)
68
68
} catch ( e ) {
69
69
if ( e instanceof Redirect ) {
70
- //console.log('REDIRECT_TO ' + e.message);
70
+ // console.log('[DEBUG] REDIRECT_TO ' + e.message);
71
71
return res . redirect ( 301 , '/' + e . message ) ;
72
72
} else {
73
73
console . error ( e )
@@ -77,16 +77,15 @@ class NotionProxy {
77
77
}
78
78
79
79
const requestHeader = req . headers
80
- requestHeader [ 'If-Modified-Since' ] = new Date ( ) . toString ( ) ;
81
80
delete requestHeader [ 'host' ]
82
81
delete requestHeader [ 'referer' ]
83
82
res . headers = requestHeader
83
+
84
84
let contentType = mime . lookup ( req . originalUrl )
85
85
if ( ! contentType ) {
86
86
contentType = 'text/html'
87
87
}
88
88
contentType = utility . getMineType ( req . originalUrl , contentType ) ;
89
-
90
89
res . set ( 'Content-Type' , contentType )
91
90
res . removeHeader ( 'Content-Security-Policy' )
92
91
res . removeHeader ( 'X-Content-Security-Policy' )
@@ -96,30 +95,31 @@ class NotionProxy {
96
95
return res . send ( cachedData ) ;
97
96
}
98
97
98
+ if ( utility . isContent ( req . originalUrl ) ) {
99
+ // Set it to If-Modified-Since now to accommodate 304
100
+ requestHeader [ 'If-Modified-Since' ] = new Date ( ) . toString ( ) ;
101
+ }
102
+
99
103
return fetch ( url , {
100
104
headers : requestHeader ,
101
105
method : 'GET' ,
102
106
} , ( error , header , body ) => {
103
- let isObjectData = false ;
104
107
105
108
// See https://github.com/stephenou/fruitionsite
106
109
if ( req . originalUrl . startsWith ( '/app' ) && req . originalUrl . endsWith ( 'js' ) ) {
107
110
res . set ( 'Content-Type' , 'application/x-javascript' )
108
111
body = body . toString ( ) . replace ( / w w w .n o t i o n .s o / g, this . DOMAIN ) . replace ( / n o t i o n .s o / g, this . DOMAIN )
109
112
} else if ( req . originalUrl . endsWith ( 'css' ) || req . originalUrl . endsWith ( 'js' ) ) {
110
113
body = body . toString ( )
111
- } else if ( req . originalUrl . startsWith ( '/image' ) || req . originalUrl . startsWith ( '/icons' ) || req . originalUrl . endsWith ( '.wasm' ) ) {
114
+ } else if ( utility . isContent ( req . originalUrl ) ) {
112
115
// Nothing
113
- isObjectData = true ;
114
116
} else if ( header !== undefined ) {
115
117
const dom = new JSDOM ( body . toString ( ) , { includeNodeLocations : true } )
116
118
this . PARSER . parse ( dom . window . document ) ;
117
119
body = dom . serialize ( ) ;
118
120
}
119
121
120
- if ( ! isObjectData ) {
121
- this . CACHE_STORE . setData ( req . originalUrl , body ) ;
122
- }
122
+ this . CACHE_STORE . setData ( req . originalUrl , body ) ;
123
123
return res . send ( body ) ;
124
124
} )
125
125
}
0 commit comments