-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathstatic.js
More file actions
62 lines (53 loc) · 1.83 KB
/
static.js
File metadata and controls
62 lines (53 loc) · 1.83 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
import fastifyStatic from '@fastify/static';
export default (fastify, options, done) => {
// 静态资源
fastify.register(fastifyStatic, {
root: options.publicDir,
prefix: '/public/',
});
fastify.register(fastifyStatic, {
root: options.appsDir,
prefix: '/apps/', // 新的访问路径前缀
decorateReply: false, // 禁用 sendFile
});
fastify.register(fastifyStatic, {
root: options.jsonDir,
prefix: '/json/', // 新的访问路径前缀
decorateReply: false, // 禁用 sendFile
});
fastify.register(fastifyStatic, {
root: options.dr2Dir,
prefix: '/js/', // 新的访问路径前缀
decorateReply: false, // 禁用 sendFile
// setHeaders: (res, path) => {
// res.setHeader('Cache-Control', 'no-store'); // 禁用缓存确保每次获取最新
// }
});
fastify.register(fastifyStatic, {
root: options.pyDir,
prefix: '/py/', // 新的访问路径前缀
decorateReply: false, // 禁用 sendFile
setHeaders: (res, path) => {
// 自定义 .py 文件的 Content-Type
if (path.endsWith('.py')) {
res.setHeader('Content-Type', 'text/plain; charset=utf-8')
}
}
});
fastify.register(fastifyStatic, {
root: options.catDir,
prefix: '/cat/', // 新的访问路径前缀
decorateReply: false, // 禁用 sendFile
});
fastify.register(fastifyStatic, {
root: options.catLibDir,
prefix: '/catLib/', // 新的访问路径前缀
decorateReply: false, // 禁用 sendFile
});
fastify.register(fastifyStatic, {
root: options.xbpqDir,
prefix: '/xbpq/', // 新的访问路径前缀
decorateReply: false, // 禁用 sendFile
});
done();
}