root commit

master
ogomez-at-wiris 2022-02-20 10:05:52 +01:00
commit ed0d0275de
7 changed files with 1441 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
packs/**

26
package.json Normal file
View File

@ -0,0 +1,26 @@
{
"name": "beatstar_api",
"version": "1.0.0",
"description": "none",
"main": "src/server.ts",
"author": "ogomez",
"license": "MIT",
"scripts": {
"dev": "nodemon src/server.ts",
"build": "rm -rf build/ && prettier --write src && tsc"
},
"dependencies": {
"axios": "^0.26.0",
"express": "^4.17.3",
"morgan": "^1.10.0",
"nodemon": "^2.0.15",
"ts-node": "^10.5.0",
"typescript": "^4.5.5"
},
"devDependencies": {
"@types/axios": "^0.14.0",
"@types/express": "^4.17.13",
"@types/morgan": "^1.9.3",
"@types/node": "^17.0.18"
}
}

7
src/routes/packs.ts Normal file
View File

@ -0,0 +1,7 @@
import express from 'express';
import PackService from '../services/pack_service';
const router = express.Router();
router.get('/packs', PackService.getPacks);
export = router;

43
src/server.ts Normal file
View File

@ -0,0 +1,43 @@
import http from 'http';
import express, { Express } from 'express';
import morgan from 'morgan';
import routes from './routes/packs';
const router: Express = express();
/** Logging */
router.use(morgan('dev'));
/** Parse the request */
router.use(express.urlencoded({ extended: false }));
/** Takes care of JSON data */
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();
});
/** Routes */
router.use('/', routes);
/** Error handling */
router.use((req, res, next) => {
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;
httpServer.listen(PORT, () => console.log(`The server is running on port ${PORT}`));

View File

@ -0,0 +1,20 @@
import { Request, Response, NextFunction } from "express";
import axios, { AxiosResponse } from "axios";
interface Pack {
name: string;
size: number;
}
export default class PackService {
public static getPacks = async (
req: Request,
res: Response,
next: NextFunction
) => {
// get a list of all packs...
return res.status(200).json({
message: "hello all packs",
});
};
}

12
tsconfig.json Normal file
View File

@ -0,0 +1,12 @@
{
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"esModuleInterop": true,
"outDir": "./build",
"rootDir": "./src",
"target": "es2021",
"skipLibCheck": true,
"strict": true
}
}

1331
yarn.lock Normal file

File diff suppressed because it is too large Load Diff