Skip to content

Commit 6b1491e

Browse files
committed
update docs
1 parent 82b8591 commit 6b1491e

File tree

6 files changed

+417
-1407
lines changed

6 files changed

+417
-1407
lines changed

Caddyfile

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,35 @@ route /http-api/echo {
88
reverse_proxy localhost:4010
99
}
1010

11-
route /http-api/openapi {
11+
route /http-api-openapi {
1212
reverse_proxy localhost:4010
1313
}
1414

15-
route /http-protocol/openapi {
15+
route /http-protocol-openapi {
1616
reverse_proxy localhost:4010
1717
}
1818

19-
route /js-playwright/openapi {
19+
route /js-playwright-openapi {
2020
reverse_proxy localhost:4010
2121
}
2222

23-
route /postman/openapi {
23+
route /postman-openapi {
24+
reverse_proxy localhost:4010
25+
}
26+
27+
route /http-api-openapi/* {
28+
reverse_proxy localhost:4010
29+
}
30+
31+
route /http-protocol-openapi/* {
32+
reverse_proxy localhost:4010
33+
}
34+
35+
route /js-playwright-openapi/* {
36+
reverse_proxy localhost:4010
37+
}
38+
39+
route /postman-openapi/* {
2440
reverse_proxy localhost:4010
2541
}
2642

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ compile:
1212
npx tsp compile ./typespec/js-playwright/main.tsp --output-dir "./tsp-output/js-playwright"
1313

1414
dev:
15-
docker run -e PORT=$(PORT) -v ./custom-server:/custom-server -p $(PORT):$(PORT) $(IMAGE_ID)
15+
docker rm -f rest-api-example
16+
docker run -e PORT=$(PORT) -v ./custom-server:/custom-server -p $(PORT):$(PORT) --name rest-api-example $(IMAGE_ID)
1617

1718
start:
1819
prism mock -m -p 4011 --host 0.0.0.0 ./tsp-output/http-api/@typespec/openapi3/openapi.1.0.yaml &

custom-server/assets/main/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
<body>
99
<h1>It works!</h1>
1010
<ul>
11-
<li><a href="/http-api/openapi">HTTP API</a></li>
12-
<li><a href="/http-protocol/openapi">HTTP Protocol</a></li>
13-
<li><a href="/js-playwright/openapi">JS Playwright</a></li>
14-
<li><a href="/postman/openapi">Postman</a></li>
11+
<li><a href="/http-api-openapi">HTTP API</a></li>
12+
<li><a href="/http-protocol-openapi">HTTP Protocol</a></li>
13+
<li><a href="/js-playwright-openapi">JS Playwright</a></li>
14+
<li><a href="/postman-openapi">Postman</a></li>
1515
</ul>
1616
</body>
1717
</html>

custom-server/src/index.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import path from 'node:path';
2+
import fp from 'fastify-plugin';
3+
import fastifySwagger from '@fastify/swagger';
4+
import swaggerUI from '@fastify/swagger-ui';
25
import fastifyStatic from '@fastify/static';
36
import formbody from '@fastify/formbody';
47

@@ -14,15 +17,39 @@ const setUpStaticAssets = (app) => {
1417
});
1518
};
1619

17-
const setupDocs = (app) => appConfig.apps.forEach((name) => {
18-
app.get(`/${name}/${appConfig.docRoute}`, (req, res) => res.sendFile(`docs/${name}/index.html`));
19-
});
20+
const setupDocs = async (app) => {
21+
const getPromises = (instance) => appConfig.apps.map(async (name) => {
22+
const openapiFilePath = path.join(dirname, '../../tsp-output/', name, '/@typespec/openapi3/openapi.1.0.yaml');
23+
return await instance.register(async (innerInstance) => {
24+
await instance.register(fastifySwagger, {
25+
mode: 'static',
26+
title: appConfig.title,
27+
exposeRoute: true,
28+
specification: {
29+
path: openapiFilePath,
30+
},
31+
// routePrefix: `${name}-${appConfig.docRoute}`,
32+
});
33+
34+
await instance.register(swaggerUI, {
35+
routePrefix: `${name}-${appConfig.docRoute}`,
36+
title: appConfig.title,
37+
staticCSP: true,
38+
transformSpecificationClone: true,
39+
theme: {
40+
title: appConfig.title,
41+
},
42+
});
43+
});
44+
})
2045

46+
await app.register(fp((instance) => Promise.all(getPromises(instance))));
47+
};
2148
export default async (app, _options) => {
2249
await app.register(formbody);
2350
setUpStaticAssets(app);
2451

25-
setupDocs(app);
52+
await setupDocs(app);
2653

2754
app.get('/http-protocol/example', (req, res) => {
2855
res

0 commit comments

Comments
 (0)