Merge branch 'main' of https://git.odit.services/lfk/backend into main
This commit is contained in:
commit
8e8aa774bc
@ -23,14 +23,20 @@
|
|||||||
"license": "CC-BY-NC-SA-4.0",
|
"license": "CC-BY-NC-SA-4.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
|
"class-transformer": "^0.3.1",
|
||||||
|
"class-validator": "^0.12.2",
|
||||||
"consola": "^2.15.0",
|
"consola": "^2.15.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"helmet": "^4.2.0",
|
"helmet": "^4.2.0",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
|
"multer": "^1.4.2",
|
||||||
"mysql": "^2.18.1",
|
"mysql": "^2.18.1",
|
||||||
"pg": "^8.5.1",
|
"pg": "^8.5.1",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"routing-controllers": "^0.9.0-alpha.6",
|
||||||
|
"routing-controllers-openapi": "^2.1.0",
|
||||||
|
"swagger-ui-express": "^4.1.5",
|
||||||
"typeorm": "^0.2.29"
|
"typeorm": "^0.2.29"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -39,6 +45,8 @@
|
|||||||
"@types/express": "^4.17.9",
|
"@types/express": "^4.17.9",
|
||||||
"@types/jsonwebtoken": "^8.5.0",
|
"@types/jsonwebtoken": "^8.5.0",
|
||||||
"@types/node": "^14.14.9",
|
"@types/node": "^14.14.9",
|
||||||
|
"@types/multer": "^1.4.4",
|
||||||
|
"@types/swagger-ui-express": "^4.1.2",
|
||||||
"dotenv-safe": "^8.2.0",
|
"dotenv-safe": "^8.2.0",
|
||||||
"husky": "^4.3.0",
|
"husky": "^4.3.0",
|
||||||
"nodemon": "^2.0.6",
|
"nodemon": "^2.0.6",
|
||||||
|
12
src/app.ts
12
src/app.ts
@ -1,15 +1,17 @@
|
|||||||
import * as dotenvSafe from "dotenv-safe";
|
|
||||||
import express from "express";
|
|
||||||
import consola from "consola";
|
|
||||||
// import * as jwt from 'jsonwebtoken';
|
|
||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
|
import * as dotenvSafe from "dotenv-safe";
|
||||||
|
import { createExpressServer } from "routing-controllers";
|
||||||
|
import consola from "consola";
|
||||||
import loaders from "./loaders/index";
|
import loaders from "./loaders/index";
|
||||||
|
|
||||||
dotenvSafe.config();
|
dotenvSafe.config();
|
||||||
const PORT = process.env.APP_PORT || 4010;
|
const PORT = process.env.APP_PORT || 4010;
|
||||||
|
|
||||||
|
const app = createExpressServer({
|
||||||
|
controllers: [__dirname + "/controllers/*.ts"],
|
||||||
|
});
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
let app = express();
|
|
||||||
await loaders(app);
|
await loaders(app);
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
consola.success(
|
consola.success(
|
||||||
|
38
src/controllers/TrackController.ts
Normal file
38
src/controllers/TrackController.ts
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import {
|
||||||
|
JsonController,
|
||||||
|
Param,
|
||||||
|
Body,
|
||||||
|
Get,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
|
Delete,
|
||||||
|
} from "routing-controllers";
|
||||||
|
import { OpenAPI } from "routing-controllers-openapi";
|
||||||
|
|
||||||
|
@JsonController()
|
||||||
|
export class TrackController {
|
||||||
|
@Get("/track")
|
||||||
|
getAll() {
|
||||||
|
return "This action returns all users";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get("/track/:id")
|
||||||
|
getOne(@Param("id") id: number) {
|
||||||
|
return "This action returns user #" + id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post("/track")
|
||||||
|
post(@Body() user: any) {
|
||||||
|
return "Saving user...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put("/track/:id")
|
||||||
|
put(@Param("id") id: number, @Body() user: any) {
|
||||||
|
return "Updating a user...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete("/track/:id")
|
||||||
|
remove(@Param("id") id: number) {
|
||||||
|
return "Removing user...";
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
import {createConnection} from "typeorm";
|
import {createConnection} from "typeorm";
|
||||||
|
|
||||||
export default async ()=> {
|
export default async ()=> {
|
||||||
return await createConnection();
|
const connection = await createConnection();
|
||||||
|
connection.synchronize();
|
||||||
|
return connection;
|
||||||
};
|
};
|
@ -1,11 +1,11 @@
|
|||||||
import expressLoader from "./express";
|
import expressLoader from "./express";
|
||||||
import routeLoader from "./routes";
|
import openapiLoader from "./openapi";
|
||||||
import databaseLoader from "./database";
|
import databaseLoader from "./database";
|
||||||
import {Application} from "express";
|
import { Application } from "express";
|
||||||
|
|
||||||
export default async (app: Application) => {
|
export default async (app: Application) => {
|
||||||
|
await databaseLoader();
|
||||||
|
await openapiLoader(app);
|
||||||
await expressLoader(app);
|
await expressLoader(app);
|
||||||
await routeLoader(app);
|
|
||||||
databaseLoader();
|
|
||||||
return app;
|
return app;
|
||||||
};
|
};
|
||||||
|
11
src/loaders/openapi.ts
Normal file
11
src/loaders/openapi.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Application } from "express";
|
||||||
|
import * as swaggerUiExpress from "swagger-ui-express";
|
||||||
|
import { getMetadataArgsStorage } from "routing-controllers";
|
||||||
|
import { routingControllersToSpec } from "routing-controllers-openapi";
|
||||||
|
|
||||||
|
export default async (app: Application) => {
|
||||||
|
const storage = getMetadataArgsStorage();
|
||||||
|
const spec = routingControllersToSpec(storage);
|
||||||
|
app.use("/docs", swaggerUiExpress.serve, swaggerUiExpress.setup(spec));
|
||||||
|
return app;
|
||||||
|
};
|
@ -1,7 +0,0 @@
|
|||||||
import {Application} from "express";
|
|
||||||
import routerMain from "../routes/index";
|
|
||||||
|
|
||||||
export default async (app: Application) => {
|
|
||||||
app.use('/api/', routerMain);
|
|
||||||
return app;
|
|
||||||
};
|
|
@ -1,14 +1,14 @@
|
|||||||
import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";
|
import { Entity, PrimaryGeneratedColumn, Column } from "typeorm";
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Track {
|
export class Track {
|
||||||
@PrimaryGeneratedColumn()
|
@PrimaryGeneratedColumn()
|
||||||
id!: number;
|
id: number;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
name!: string;
|
name: string;
|
||||||
|
|
||||||
//Length in meters
|
//Length in meters
|
||||||
@Column()
|
@Column()
|
||||||
length!: string;
|
length: string;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
import Router from 'express';
|
|
||||||
import v1 from "./v1/index";
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
router.use('/v1/', v1);
|
|
||||||
router.use('*', (req, res) => {
|
|
||||||
return res.status(404).send('404');
|
|
||||||
});
|
|
||||||
export default router;
|
|
@ -1,9 +0,0 @@
|
|||||||
import Router from 'express';
|
|
||||||
import track from "./track";
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
router.use("/track", track)
|
|
||||||
router.use('/*/', (req, res) => {
|
|
||||||
return res.send('Express + TypeScript Server');
|
|
||||||
});
|
|
||||||
export default router;
|
|
@ -1,29 +0,0 @@
|
|||||||
import {Router} from 'express';
|
|
||||||
import {getConnection} from "typeorm";
|
|
||||||
import {Track} from "../../models/Track"
|
|
||||||
|
|
||||||
var router = Router();
|
|
||||||
//const manager = getConnection().manager;
|
|
||||||
|
|
||||||
router.get('/', async (req, res, next) => {
|
|
||||||
//let tracks = manager.find(Track);
|
|
||||||
//res.send(tracks);
|
|
||||||
res.sendStatus(200);
|
|
||||||
});
|
|
||||||
|
|
||||||
router.post('/', async (req, res, next) => {
|
|
||||||
res.sendStatus(200);
|
|
||||||
/*let track = new Track();
|
|
||||||
track.length=req.body.length;
|
|
||||||
track.name=req.body.name;
|
|
||||||
|
|
||||||
try {
|
|
||||||
let newUser = await manager.save(track);
|
|
||||||
res.send(newUser);
|
|
||||||
} catch (error) {
|
|
||||||
res.send(error);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
export default router;
|
|
Loading…
x
Reference in New Issue
Block a user