fix: Add base path constant
parent
20c979fc12
commit
9ea34bdc30
|
@ -1,13 +1,13 @@
|
|||
import http from 'http';
|
||||
import express, { Express } from 'express';
|
||||
import morgan from 'morgan';
|
||||
import { packRoutes } from './routes/packs';
|
||||
import PackService from './services/pack_service';
|
||||
import http from "http";
|
||||
import express, { Express } from "express";
|
||||
import morgan from "morgan";
|
||||
import { packRoutes } from "./routes/packs";
|
||||
import PackService from "./services/pack_service";
|
||||
|
||||
const router: Express = express();
|
||||
|
||||
/** Logging */
|
||||
router.use(morgan('dev'));
|
||||
router.use(morgan("dev"));
|
||||
/** Parse the request */
|
||||
router.use(express.urlencoded({ extended: false }));
|
||||
/** Takes care of JSON data */
|
||||
|
@ -15,33 +15,37 @@ router.use(express.json());
|
|||
|
||||
/** RULES OF OUR API */
|
||||
router.use((req, res, next) => {
|
||||
// set the CORS policy
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
// set the CORS headers
|
||||
res.header('Access-Control-Allow-Headers', 'origin, X-Requested-With,Content-Type,Accept, Authorization');
|
||||
// set the CORS method headers
|
||||
if (req.method === 'OPTIONS') {
|
||||
res.header('Access-Control-Allow-Methods', 'GET POST');
|
||||
return res.status(200).json({});
|
||||
}
|
||||
next();
|
||||
// set the CORS policy
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
// set the CORS headers
|
||||
res.header(
|
||||
"Access-Control-Allow-Headers",
|
||||
"origin, X-Requested-With,Content-Type,Accept, Authorization"
|
||||
);
|
||||
// set the CORS method headers
|
||||
if (req.method === "OPTIONS") {
|
||||
res.header("Access-Control-Allow-Methods", "GET POST");
|
||||
return res.status(200).json({});
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
/** Routes */
|
||||
router.use('/', packRoutes);
|
||||
router.use("/", packRoutes);
|
||||
|
||||
/** Error handling */
|
||||
router.use((req, res, next) => {
|
||||
const error = new Error('not found');
|
||||
return res.status(404).json({
|
||||
message: error.message
|
||||
});
|
||||
const error = new Error("not found");
|
||||
return res.status(404).json({
|
||||
message: error.message,
|
||||
});
|
||||
});
|
||||
|
||||
/** Server */
|
||||
const httpServer = http.createServer(router);
|
||||
const PORT: any = process.env.PORT ?? 6060;
|
||||
PackService.getInitialList().then(() => {
|
||||
httpServer.listen(PORT, () => console.log(`The server is running on port ${PORT}`));
|
||||
httpServer.listen(PORT, () =>
|
||||
console.log(`The server is running on port ${PORT}`)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
import { Request, Response, NextFunction } from "express";
|
||||
import fs from "fs";
|
||||
import axios, { AxiosResponse } from "axios";
|
||||
import * as fsWalk from "@nodelib/fs.walk";
|
||||
const PACK_BASE_PATH = '';
|
||||
|
||||
interface Pack {
|
||||
name: string;
|
||||
size: number;
|
||||
bpm: string;
|
||||
}
|
||||
|
||||
export default class PackService {
|
||||
public static getInitialList = async () => {
|
||||
const packs = await fs.readdirSync("packs");
|
||||
const packs = await fs.readdirSync(PACK_BASE_PATH+"packs");
|
||||
console.log(packs);
|
||||
};
|
||||
|
||||
public static getPacks = async (
|
||||
req: Request,
|
||||
res: Response,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"compilerOptions": {
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "commonjs",
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src",
|
||||
"target": "es2021",
|
||||
|
|
Loading…
Reference in New Issue