Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/fixtures/edit-asyncawait-4151/index.ts
13399 views
1
import express, { Request, Response } from 'express';
2
import dotenv from 'dotenv';
3
import swaggerUi from 'swagger-ui-express';
4
import * as OpenApiValidator from 'express-openapi-validator';
5
import cors from 'cors';
6
const openApiSpecification = require('../.well-known/openapi.json');
7
8
export default express;
9
const app = express();
10
const categoryId = 'a5ae013c-14a1-4c2d-a731-47fbbd0ba527';
11
app.use(cors());
12
dotenv.config();
13
14
interface Show {
15
id: string;
16
title: string;
17
description: string;
18
episodes: Episode[];
19
image: string;
20
}
21
22
interface Episode {
23
description: string;
24
id: string;
25
title: string;
26
published: string;
27
}
28
29
app.use('/.well-known', express.static('.well-known'));
30
app.use('/docs', swaggerUi.serve, swaggerUi.setup(openApiSpecification));
31
32
app.get('/shows', async (_req: Request, res: Response) => {
33
const params = new URLSearchParams({
34
limit: '6',
35
categoryId
36
});
37
const response = await fetch(`${process.env.PODCAST_URL}shows?${params}`);
38
const json = await response.json();
39
res.send(json);
40
});
41
42
app.get('/shows/:id', async (req: Request, res: Response) => {
43
const response = await fetch(`${process.env.PODCAST_URL}shows/${req.params.id}`);
44
const json: Show = await response.json();
45
res.send(json);
46
});
47
48
app.get('/episodes/:id/summary', (req: Request, res: Response) => {
49
fetch(`${process.env.PODCAST_URL}episodes/${req.params.id}`).then((response) => {
50
response.json().then((json: Episode) => {
51
const summary = json.description;
52
res.send({ summary });
53
});
54
}, (error) => {
55
console.log(error);
56
res.status(500).send({ error });
57
});
58
});
59
60
app.get('/', (_req: Request, res: Response) => {
61
res.send('Friendly Podcast Server is running!');
62
});
63
64
app.use(
65
OpenApiValidator.middleware({
66
apiSpec: './.well-known/openapi.json',
67
validateRequests: true,
68
validateResponses: true,
69
ignorePaths: /\/\.well-known\// // Add this line to ignore the .well-known folder
70
}),
71
);
72
73
const port = 8080;
74
app.listen(port, () => {
75
console.log(`⚡️[server]: Server is running at http://localhost:${port}`);
76
});
77
78