PAPI-4: Inital Commit for PlutoDev REST API

This commit is contained in:
Patrick Müller 2021-02-16 22:55:50 +01:00
commit 57059b0b2f
7 changed files with 2020 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# IntelliJ Files
.idea
**/*.iml

27
app.ts Normal file
View File

@ -0,0 +1,27 @@
import express from 'express';
import * as http from 'http';
import * as bodyparser from 'body-parser';
import {CommonRoutesConfig} from './src/common/common.routes.config';
import {GeneralInfoRoutes} from './src/models/dhbw-service/generalInfo.routes.config';
const app: express.Application = express();
const server: http.Server = http.createServer(app);
const port: Number = 3000;
const routes: Array<CommonRoutesConfig> = [];
// here we are adding middleware to parse all incoming requests as JSON
app.use(bodyparser.json());
// here we are adding the UserRoutes to our array,
// after sending the Express.js application object to have the routes added to our app!
routes.push(new GeneralInfoRoutes(app));
// this is a simple route to make sure everything is working properly
app.get('/', (req: express.Request, res: express.Response) => {
res.status(200).send('Welcome to the Pluto Development REST API!');
});
server.listen(port, () => {
console.log('Server listening on Port 3000');
});

1920
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

25
package.json Normal file
View File

@ -0,0 +1,25 @@
{
"name": "PlutoDevExpressAPI",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "tsc && node ./dist/app.js",
"debug": "export DEBUG=* && npm run start",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"debug": "^4.3.1",
"express": "^4.17.1"
},
"devDependencies": {
"@types/debug": "^4.1.5",
"@types/express": "^4.17.11",
"source-map-support": "^0.5.19",
"tslint": "^6.1.3",
"typescript": "^4.1.5"
}
}

View File

@ -0,0 +1,15 @@
import express from 'express';
export abstract class CommonRoutesConfig {
app: express.Application;
name: string;
constructor(app: express.Application, name: string) {
this.app = app;
this.name = name;
this.configureRoutes();
}
getName() {
return this.name;
}
abstract configureRoutes(): express.Application;
}

View File

@ -0,0 +1,20 @@
import {CommonRoutesConfig} from '../../common/common.routes.config';
import express from 'express';
export class GeneralInfoRoutes extends CommonRoutesConfig {
constructor(app: express.Application) {
super(app, 'GeneralInfoRoutes');
}
configureRoutes() {
this.app.route(`/dhbw-service/generalInfo`)
.get((req: express.Request, res: express.Response) => {
res.status(200).send(`List of users`);
})
.post((req: express.Request, res: express.Response) => {
res.status(200).send(`Post to users`);
});
return this.app;
}
}

10
tsconfig.json Normal file
View File

@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"outDir": "./dist",
"strict": true,
"esModuleInterop": true,
"inlineSourceMap": true
}
}