forked from hplush/slowreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
29 lines (25 loc) · 644 Bytes
/
proxy.ts
File metadata and controls
29 lines (25 loc) · 644 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import type { BaseServer } from '@logux/server'
import {
createProxy,
DEFAULT_PROXY_CONFIG,
type ProxyConfig
} from '@slowreader/proxy'
import { config } from '../lib/config.ts'
export default (server: BaseServer, opts: Partial<ProxyConfig> = {}): void => {
let allowsFrom = config.proxyOrigin ?? opts.allowsFrom
if (!allowsFrom) return
server.logger.info('CORS proxy is enabled')
let proxy = createProxy({
...DEFAULT_PROXY_CONFIG,
...opts,
allowsFrom
})
server.http((req, res) => {
if (req.url!.startsWith('/proxy/')) {
proxy(req, res)
return true
} else {
return false
}
})
}