Skip to content

Commit 47282f6

Browse files
committed
refactor: add express endpoint docstrings
1 parent 7fb7847 commit 47282f6

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

express/index.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1-
import { readFileSync } from 'fs'
2-
import glob from 'glob'
3-
import express from 'express'
1+
/**
2+
* @file A simple express server variant of GRS can run GRS in a docker container.
3+
* This is not intended to be used in the development; please use the `vercel dev`
4+
* command instead.
5+
*/
6+
import { readFileSync } from "fs";
7+
import glob from "glob";
8+
import express from "express";
49

5-
const vercelConfig = JSON.parse(readFileSync('./vercel.json', 'utf8'))
6-
const vercelFunctions = Object.keys(vercelConfig.functions)
10+
const vercelConfig = JSON.parse(readFileSync("./vercel.json", "utf8"));
11+
const vercelFunctions = Object.keys(vercelConfig.functions);
712

8-
const port = process.env.PORT || 3000
9-
const app = express()
13+
const port = process.env.PORT || 3000;
14+
const app = express();
1015

11-
const files = vercelFunctions.map(gl => glob.sync(gl)).flat()
12-
await loadApiRoutes(files)
16+
const files = vercelFunctions.map((gl) => glob.sync(gl)).flat();
17+
await loadApiRoutes(files);
1318

1419
app.listen(port, () => {
15-
console.log(`Server listening on port ${port}`)
16-
})
20+
console.log(`Server listening on port ${port}`);
21+
});
1722

23+
/**
24+
* Loads all api routes from the `api` directory.
25+
* @param {string[]} files Api endpoint files.
26+
*/
1827
async function loadApiRoutes(files) {
1928
for (const file of files) {
20-
const route = `/${file.replace('.js', '').replace('index', '')}`
21-
console.log(`Loading route '${route}' with handler from '${file}'`)
22-
const handler = await import(`../${file}`)
23-
app.get(route, handler.default)
29+
const route = `/${file.replace(".js", "").replace("index", "")}`;
30+
console.log(`Loading route '${route}' with handler from '${file}'`);
31+
const handler = await import(`../${file}`);
32+
app.get(route, handler.default);
2433
}
2534
}

0 commit comments

Comments
 (0)