Compare commits
No commits in common. "3ce9a0b21a050095d93643bab453375c4b889ca6" and "b5cf040cf0975f3a1e5ba60e8c34bbd23bc97c91" have entirely different histories.
3ce9a0b21a
...
b5cf040cf0
@ -23,20 +23,14 @@
|
|||||||
"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": {
|
||||||
@ -45,8 +39,6 @@
|
|||||||
"@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",
|
||||||
|
10
src/app.ts
10
src/app.ts
@ -1,17 +1,15 @@
|
|||||||
import "reflect-metadata";
|
|
||||||
import * as dotenvSafe from "dotenv-safe";
|
import * as dotenvSafe from "dotenv-safe";
|
||||||
import { createExpressServer } from "routing-controllers";
|
import express from "express";
|
||||||
import consola from "consola";
|
import consola from "consola";
|
||||||
|
// import * as jwt from 'jsonwebtoken';
|
||||||
|
import "reflect-metadata";
|
||||||
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(
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
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,11 +1,11 @@
|
|||||||
import expressLoader from "./express";
|
import expressLoader from "./express";
|
||||||
import openapiLoader from "./openapi";
|
import routeLoader from "./routes";
|
||||||
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 databaseLoader();
|
||||||
await openapiLoader(app);
|
|
||||||
await expressLoader(app);
|
await expressLoader(app);
|
||||||
|
await routeLoader(app);
|
||||||
return app;
|
return app;
|
||||||
};
|
};
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
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;
|
|
||||||
};
|
|
7
src/loaders/routes.ts
Normal file
7
src/loaders/routes.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import {Application} from "express";
|
||||||
|
import routerMain from "../routes/index";
|
||||||
|
|
||||||
|
export default async (app: Application) => {
|
||||||
|
app.use('/api/', routerMain);
|
||||||
|
return app;
|
||||||
|
};
|
0
src/routes/.gitkeep
Normal file
0
src/routes/.gitkeep
Normal file
9
src/routes/index.ts
Normal file
9
src/routes/index.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
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;
|
9
src/routes/v1/index.ts
Normal file
9
src/routes/v1/index.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
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;
|
27
src/routes/v1/track.ts
Normal file
27
src/routes/v1/track.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import {Router} from 'express';
|
||||||
|
import {getConnection} from "typeorm";
|
||||||
|
import {Track} from "../../models/Track"
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.get('/', async (req, res, next) => {
|
||||||
|
const trackManager = await getConnection().getRepository(Track);
|
||||||
|
let tracks = trackManager.count();
|
||||||
|
return res.send(tracks);
|
||||||
|
});
|
||||||
|
|
||||||
|
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