-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathhelpers.ts
More file actions
32 lines (31 loc) · 802 Bytes
/
helpers.ts
File metadata and controls
32 lines (31 loc) · 802 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
30
31
32
import * as http from 'http';
import { join } from 'path';
import fastify, { FastifyInstance } from 'fastify';
import fastifyStatic from 'fastify-static';
export const setupStaticServer = async (
rss?: string,
index?: string,
): Promise<FastifyInstance> => {
const app = fastify({ logger: false });
app.register(fastifyStatic, {
root: join(__dirname, 'fixture'),
prefix: '/',
setHeaders(res: http.ServerResponse, path: string): void {
if (rss && path.indexOf(rss) > -1) {
res.setHeader('content-type', 'application/rss+xml');
}
},
});
if (rss) {
app.get('/rss.xml', (req, res) => {
res.sendFile(rss);
});
}
if (index) {
app.get('/', (req, res) => {
res.sendFile(index);
});
}
await app.listen(6789);
return app;
};