Skip to content

Commit 8e15bb3

Browse files
committed
fix: run prettier
1 parent 9fc1402 commit 8e15bb3

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

src/server.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
1-
import express from 'express';
2-
import cors from 'cors';
3-
import { readFile } from 'fs/promises';
1+
import express from "express";
2+
import cors from "cors";
3+
import { readFile } from "fs/promises";
44
import { crawl, write } from "./core.js";
5-
import { Config, configSchema } from './config.js';
6-
import { configDotenv } from 'dotenv';
7-
import swaggerUi from 'swagger-ui-express';
5+
import { Config, configSchema } from "./config.js";
6+
import { configDotenv } from "dotenv";
7+
import swaggerUi from "swagger-ui-express";
88
// @ts-ignore
9-
import swaggerDocument from '../swagger-output.json' assert { type: 'json' };
9+
import swaggerDocument from "../swagger-output.json" assert { type: "json" };
1010

1111
configDotenv();
1212

1313
const app = express();
1414
const port = Number(process.env.API_PORT) || 3000;
15-
const hostname = process.env.API_HOST || 'localhost';
15+
const hostname = process.env.API_HOST || "localhost";
1616

1717
app.use(cors());
1818
app.use(express.json());
19-
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
19+
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
2020

2121
// Define a POST route to accept config and run the crawler
22-
app.post('/crawl', async (req, res) => {
23-
const config: Config = req.body;
24-
try {
25-
const validatedConfig = configSchema.parse(config);
26-
await crawl(validatedConfig);
27-
await write(validatedConfig);
28-
const outputFileContent = await readFile(validatedConfig.outputFileName, 'utf-8');
29-
res.contentType('application/json');
30-
return res.send(outputFileContent);
31-
} catch (error) {
32-
return res.status(500).json({ message: 'Error occurred during crawling', error });
33-
}
22+
app.post("/crawl", async (req, res) => {
23+
const config: Config = req.body;
24+
try {
25+
const validatedConfig = configSchema.parse(config);
26+
await crawl(validatedConfig);
27+
await write(validatedConfig);
28+
const outputFileContent = await readFile(
29+
validatedConfig.outputFileName,
30+
"utf-8",
31+
);
32+
res.contentType("application/json");
33+
return res.send(outputFileContent);
34+
} catch (error) {
35+
return res
36+
.status(500)
37+
.json({ message: "Error occurred during crawling", error });
38+
}
3439
});
3540

3641
app.listen(port, hostname, () => {
37-
console.log(`API server listening at http://${hostname}:${port}`);
42+
console.log(`API server listening at http://${hostname}:${port}`);
3843
});
3944

4045
export default app;

swagger.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import swaggerAutogen from 'swagger-autogen';
1+
import swaggerAutogen from "swagger-autogen";
22

33
const doc = {
4-
info: {
5-
title: 'GPT Crawler API',
6-
description: 'GPT Crawler'
7-
},
8-
host: 'localhost:5000'
4+
info: {
5+
title: "GPT Crawler API",
6+
description: "GPT Crawler",
7+
},
8+
host: "localhost:5000",
99
};
1010

11-
const outputFile = 'swagger-output.json';
12-
const routes = ['./src/server.ts'];
11+
const outputFile = "swagger-output.json";
12+
const routes = ["./src/server.ts"];
1313

1414
swaggerAutogen()(outputFile, routes, doc);

0 commit comments

Comments
 (0)