Path: blob/main/extensions/copilot/test/simulation/fixtures/edit-slice-4149/index.ts
13399 views
import express, { Request, Response } from 'express';1import dotenv from 'dotenv';2import swaggerUi from 'swagger-ui-express';3import * as OpenApiValidator from 'express-openapi-validator';4import cors from 'cors';5const openApiSpecification = require('../.well-known/openapi.json');67export default express;8const app = express();9const categoryId = 'a5ae013c-14a1-4c2d-a731-47fbbd0ba527';10app.use(cors());11dotenv.config();1213interface Show {14id: string;15title: string;16description: string;17episodes: Episode[];18image: string;19}2021interface Episode {22description: string;23id: string;24title: string;25published: string;26}2728app.use('/.well-known', express.static('.well-known'));29app.use('/docs', swaggerUi.serve, swaggerUi.setup(openApiSpecification));3031app.get('/shows', async (_req: Request, res: Response) => {32const params = new URLSearchParams({33limit: '6',34categoryId35});36const response = await fetch(`${process.env.PODCAST_URL}shows?${params}`);37const json = await response.json();38res.send(json);39});4041app.get('/shows/:id', async (req: Request, res: Response) => {42const response = await fetch(`${process.env.PODCAST_URL}shows/${req.params.id}`);43const json: Show = await response.json();44res.send(json);45});4647app.get('/episodes/:id/summary', async (req: Request, res: Response) => {48try {49const response = await fetch(`${process.env.PODCAST_URL}episodes/${req.params.id}`);50const json: Episode = await response.json();51const summary = json.description;52res.send({ summary });53} catch (error) {54console.log(error);55res.status(500).send({ error });56}57});5859app.get('/', (_req: Request, res: Response) => {60res.send('Friendly Podcast Server is running!');61});6263app.use(64OpenApiValidator.middleware({65apiSpec: './.well-known/openapi.json',66validateRequests: true,67validateResponses: true,68ignorePaths: /\/\.well-known\// // Add this line to ignore the .well-known folder69}),70);7172const port = 8080;73app.listen(port, () => {74console.log(`⚡️[server]: Server is running at http://localhost:${port}`);75});767778