Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dzencot committed Oct 29, 2024
1 parent 82b8591 commit 6b1491e
Show file tree
Hide file tree
Showing 6 changed files with 417 additions and 1,407 deletions.
24 changes: 20 additions & 4 deletions Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,35 @@ route /http-api/echo {
reverse_proxy localhost:4010
}

route /http-api/openapi {
route /http-api-openapi {
reverse_proxy localhost:4010
}

route /http-protocol/openapi {
route /http-protocol-openapi {
reverse_proxy localhost:4010
}

route /js-playwright/openapi {
route /js-playwright-openapi {
reverse_proxy localhost:4010
}

route /postman/openapi {
route /postman-openapi {
reverse_proxy localhost:4010
}

route /http-api-openapi/* {
reverse_proxy localhost:4010
}

route /http-protocol-openapi/* {
reverse_proxy localhost:4010
}

route /js-playwright-openapi/* {
reverse_proxy localhost:4010
}

route /postman-openapi/* {
reverse_proxy localhost:4010
}

Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ compile:
npx tsp compile ./typespec/js-playwright/main.tsp --output-dir "./tsp-output/js-playwright"

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

start:
prism mock -m -p 4011 --host 0.0.0.0 ./tsp-output/http-api/@typespec/openapi3/openapi.1.0.yaml &
Expand Down
8 changes: 4 additions & 4 deletions custom-server/assets/main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<body>
<h1>It works!</h1>
<ul>
<li><a href="/http-api/openapi">HTTP API</a></li>
<li><a href="/http-protocol/openapi">HTTP Protocol</a></li>
<li><a href="/js-playwright/openapi">JS Playwright</a></li>
<li><a href="/postman/openapi">Postman</a></li>
<li><a href="/http-api-openapi">HTTP API</a></li>
<li><a href="/http-protocol-openapi">HTTP Protocol</a></li>
<li><a href="/js-playwright-openapi">JS Playwright</a></li>
<li><a href="/postman-openapi">Postman</a></li>
</ul>
</body>
</html>
35 changes: 31 additions & 4 deletions custom-server/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import path from 'node:path';
import fp from 'fastify-plugin';
import fastifySwagger from '@fastify/swagger';
import swaggerUI from '@fastify/swagger-ui';
import fastifyStatic from '@fastify/static';
import formbody from '@fastify/formbody';

Expand All @@ -14,15 +17,39 @@ const setUpStaticAssets = (app) => {
});
};

const setupDocs = (app) => appConfig.apps.forEach((name) => {
app.get(`/${name}/${appConfig.docRoute}`, (req, res) => res.sendFile(`docs/${name}/index.html`));
});
const setupDocs = async (app) => {
const getPromises = (instance) => appConfig.apps.map(async (name) => {
const openapiFilePath = path.join(dirname, '../../tsp-output/', name, '/@typespec/openapi3/openapi.1.0.yaml');
return await instance.register(async (innerInstance) => {
await instance.register(fastifySwagger, {
mode: 'static',
title: appConfig.title,
exposeRoute: true,
specification: {
path: openapiFilePath,
},
// routePrefix: `${name}-${appConfig.docRoute}`,
});

await instance.register(swaggerUI, {
routePrefix: `${name}-${appConfig.docRoute}`,
title: appConfig.title,
staticCSP: true,
transformSpecificationClone: true,
theme: {
title: appConfig.title,
},
});
});
})

await app.register(fp((instance) => Promise.all(getPromises(instance))));
};
export default async (app, _options) => {
await app.register(formbody);
setUpStaticAssets(app);

setupDocs(app);
await setupDocs(app);

app.get('/http-protocol/example', (req, res) => {
res
Expand Down
Loading

0 comments on commit 6b1491e

Please sign in to comment.