feat: Get initial list of files in packs folder on startup
parent
ed0d0275de
commit
20c979fc12
|
@ -8,8 +8,9 @@
|
|||
"scripts": {
|
||||
"dev": "nodemon src/server.ts",
|
||||
"build": "rm -rf build/ && prettier --write src && tsc"
|
||||
},
|
||||
},
|
||||
"dependencies": {
|
||||
"@nodelib/fs.walk": "^1.2.8",
|
||||
"axios": "^0.26.0",
|
||||
"express": "^4.17.3",
|
||||
"morgan": "^1.10.0",
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import express from 'express';
|
||||
import PackService from '../services/pack_service';
|
||||
const router = express.Router();
|
||||
export const packRoutes = express.Router();
|
||||
|
||||
router.get('/packs', PackService.getPacks);
|
||||
|
||||
export = router;
|
||||
packRoutes.get('/packs', PackService.getPacks);
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import http from 'http';
|
||||
import express, { Express } from 'express';
|
||||
import morgan from 'morgan';
|
||||
import routes from './routes/packs';
|
||||
import { packRoutes } from './routes/packs';
|
||||
import PackService from './services/pack_service';
|
||||
|
||||
const router: Express = express();
|
||||
|
||||
|
@ -27,7 +28,7 @@ router.use((req, res, next) => {
|
|||
});
|
||||
|
||||
/** Routes */
|
||||
router.use('/', routes);
|
||||
router.use('/', packRoutes);
|
||||
|
||||
/** Error handling */
|
||||
router.use((req, res, next) => {
|
||||
|
@ -40,4 +41,7 @@ router.use((req, res, next) => {
|
|||
/** Server */
|
||||
const httpServer = http.createServer(router);
|
||||
const PORT: any = process.env.PORT ?? 6060;
|
||||
httpServer.listen(PORT, () => console.log(`The server is running on port ${PORT}`));
|
||||
PackService.getInitialList().then(() => {
|
||||
httpServer.listen(PORT, () => console.log(`The server is running on port ${PORT}`));
|
||||
});
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { Request, Response, NextFunction } from "express";
|
||||
import fs from "fs";
|
||||
import axios, { AxiosResponse } from "axios";
|
||||
import * as fsWalk from "@nodelib/fs.walk";
|
||||
|
||||
interface Pack {
|
||||
name: string;
|
||||
|
@ -7,6 +9,10 @@ interface Pack {
|
|||
}
|
||||
|
||||
export default class PackService {
|
||||
public static getInitialList = async () => {
|
||||
const packs = await fs.readdirSync("packs");
|
||||
console.log(packs);
|
||||
};
|
||||
public static getPacks = async (
|
||||
req: Request,
|
||||
res: Response,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src",
|
||||
|
|
45
yarn.lock
45
yarn.lock
|
@ -14,6 +14,27 @@
|
|||
dependencies:
|
||||
"@cspotcode/source-map-consumer" "0.8.0"
|
||||
|
||||
"@nodelib/fs.scandir@2.1.5":
|
||||
version "2.1.5"
|
||||
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5"
|
||||
integrity sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==
|
||||
dependencies:
|
||||
"@nodelib/fs.stat" "2.0.5"
|
||||
run-parallel "^1.1.9"
|
||||
|
||||
"@nodelib/fs.stat@2.0.5":
|
||||
version "2.0.5"
|
||||
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz#5bd262af94e9d25bd1e71b05deed44876a222e8b"
|
||||
integrity sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==
|
||||
|
||||
"@nodelib/fs.walk@^1.2.8":
|
||||
version "1.2.8"
|
||||
resolved "https://registry.yarnpkg.com/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz#e95737e8bb6746ddedf69c556953494f196fe69a"
|
||||
integrity sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==
|
||||
dependencies:
|
||||
"@nodelib/fs.scandir" "2.1.5"
|
||||
fastq "^1.6.0"
|
||||
|
||||
"@sindresorhus/is@^0.14.0":
|
||||
version "0.14.0"
|
||||
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea"
|
||||
|
@ -511,6 +532,13 @@ express@^4.17.3:
|
|||
utils-merge "1.0.1"
|
||||
vary "~1.1.2"
|
||||
|
||||
fastq@^1.6.0:
|
||||
version "1.13.0"
|
||||
resolved "https://registry.yarnpkg.com/fastq/-/fastq-1.13.0.tgz#616760f88a7526bdfc596b7cab8c18938c36b98c"
|
||||
integrity sha512-YpkpUnK8od0o1hmeSc7UUs/eB/vIPWJYjKck2QKIzAf71Vm1AAQ3EbuZB3g2JIy+pg+ERD0vqI79KyZiB2e2Nw==
|
||||
dependencies:
|
||||
reusify "^1.0.4"
|
||||
|
||||
fill-range@^7.0.1:
|
||||
version "7.0.1"
|
||||
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
|
||||
|
@ -986,6 +1014,11 @@ qs@6.9.7:
|
|||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.7.tgz#4610846871485e1e048f44ae3b94033f0e675afe"
|
||||
integrity sha512-IhMFgUmuNpyRfxA90umL7ByLlgRXu6tIfKPpF5TmcfRLlLCckfP/g3IQmju6jjpu+Hh8rA+2p6A27ZSPOOHdKw==
|
||||
|
||||
queue-microtask@^1.2.2:
|
||||
version "1.2.3"
|
||||
resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"
|
||||
integrity sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==
|
||||
|
||||
range-parser@~1.2.1:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031"
|
||||
|
@ -1039,6 +1072,18 @@ responselike@^1.0.2:
|
|||
dependencies:
|
||||
lowercase-keys "^1.0.0"
|
||||
|
||||
reusify@^1.0.4:
|
||||
version "1.0.4"
|
||||
resolved "https://registry.yarnpkg.com/reusify/-/reusify-1.0.4.tgz#90da382b1e126efc02146e90845a88db12925d76"
|
||||
integrity sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==
|
||||
|
||||
run-parallel@^1.1.9:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.2.0.tgz#66d1368da7bdf921eb9d95bd1a9229e7f21a43ee"
|
||||
integrity sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==
|
||||
dependencies:
|
||||
queue-microtask "^1.2.2"
|
||||
|
||||
safe-buffer@5.1.2:
|
||||
version "5.1.2"
|
||||
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
|
||||
|
|
Loading…
Reference in New Issue