-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-server.ts
More file actions
86 lines (73 loc) · 3.21 KB
/
basic-server.ts
File metadata and controls
86 lines (73 loc) · 3.21 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { OMSSServer } from '../src' // replace this in your own implementation with '@omss/framework'
import 'dotenv/config'
async function main() {
const server = new OMSSServer({
name: 'OMSS Backend',
version: '1.0.0',
// note: 'You can add a custom note here.'
// Network
host: process.env.HOST ?? 'localhost',
port: Number(process.env.PORT ?? 3000),
publicUrl: process.env.PUBLIC_URL,
// Cache (memory for dev, Redis for prod)
cache: {
type: (process.env.CACHE_TYPE as 'memory' | 'redis') ?? 'memory',
ttl: {
sources: 60 * 60,
subtitles: 60 * 60 * 24,
},
redis: {
host: process.env.REDIS_HOST ?? 'localhost',
port: Number(process.env.REDIS_PORT ?? 6379),
password: process.env.REDIS_PASSWORD,
},
},
// TMDB (required)
tmdb: {
apiKey: process.env.TMDB_API_KEY!,
cacheTTL: 24 * 60 * 60, // 24h
},
proxyConfig: {
knownThirdPartyProxies: {
'hls1.vid1.site': [/\/proxy\/(.+)$/],
'madplay.site': [/\/api\/[^/]+\/proxy\?url=(.+)$/],
'*': [/\/proxy\/(.+)$/, /\/m3u8-proxy\?url=(.+?)(&|$)/],
},
streamPatterns: [
/\.mp4($|\?)/i,
/\.mkv($|\?)/i,
/\.webm($|\?)/i,
/\.avi($|\?)/i,
/\.mov($|\?)/i,
// here you could add more patterns for other video formats
// or downloader domains (like pixeldrain, where the video format is not in the url)
],
},
// You can override the default cors settings, by passing your own fastify cors options here. By default, it allows all origins.
/*
cors: {
origin: '*',
methods: ['GET', 'OPTIONS', 'HEAD'],
allowedHeaders: ['Content-Type', 'Authorization', 'Range', 'Accept'],
exposedHeaders: ['Content-Length', 'Content-Type', 'Content-Range', 'Accept-Ranges'],
}
*/
})
// Register providers
const registry = server.getRegistry()
// Your custom providers (auto-discovered from ./src/providers/)
await registry.discoverProviders('./examples/providers')
// before starting the server, you can also modify any fastify instance settings, by getting the instance via server.getFastifyInstance() and calling any of its methods. For example, to add a custom route:
/*
const fastify = server.getFastifyInstance()
fastify.get('/custom-route', async (request, reply) => {
return { message: 'This is a custom route!' }
})
or add a custom hook/middleware/fastify plugin, etc...
NOTE: If you want to add custom routes, hooks, or plugins *before mapping the default routes* (required for oauth2 for example), you cannot do this yet. If you wish to do this, please open an issue or submit a PR to add a new option in the server constructor that allows you to do this. For now, you can add custom routes, hooks, or plugins after the server has started.
*/
await server.start()
}
main().catch(() => {
process.exit(1)
})