parent
b5cf040cf0
commit
8cbcfe7fbb
|
@ -23,14 +23,18 @@
|
|||
"license": "CC-BY-NC-SA-4.0",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.19.0",
|
||||
"class-transformer": "^0.3.1",
|
||||
"class-validator": "^0.12.2",
|
||||
"consola": "^2.15.0",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.17.1",
|
||||
"helmet": "^4.2.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"multer": "^1.4.2",
|
||||
"mysql": "^2.18.1",
|
||||
"pg": "^8.5.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"routing-controllers": "^0.9.0-alpha.6",
|
||||
"typeorm": "^0.2.29"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -38,7 +42,8 @@
|
|||
"@types/dotenv-safe": "^8.1.1",
|
||||
"@types/express": "^4.17.9",
|
||||
"@types/jsonwebtoken": "^8.5.0",
|
||||
"@types/node": "^14.14.9",
|
||||
"@types/node": "^14.14.9",
|
||||
"@types/multer": "^1.4.4",
|
||||
"dotenv-safe": "^8.2.0",
|
||||
"husky": "^4.3.0",
|
||||
"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 * as dotenvSafe from "dotenv-safe";
|
||||
import { createExpressServer } from "routing-controllers";
|
||||
import consola from "consola";
|
||||
import loaders from "./loaders/index";
|
||||
|
||||
dotenvSafe.config();
|
||||
const PORT = process.env.APP_PORT || 4010;
|
||||
|
||||
const app = createExpressServer({
|
||||
controllers: [__dirname + "/controllers/*.ts"],
|
||||
});
|
||||
|
||||
async function main() {
|
||||
let app = express();
|
||||
await loaders(app);
|
||||
app.listen(PORT, () => {
|
||||
consola.success(
|
||||
|
|
|
@ -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,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,27 +0,0 @@
|
|||
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…
Reference in New Issue