Added a simple hapi endpoint
This commit is contained in:
parent
51f22807a1
commit
1a43c6a295
|
@ -17,6 +17,8 @@
|
|||
"author": "ODIT.Services",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@hapi/hapi": "^20.0.1",
|
||||
"@types/hapi__hapi": "^20.0.2",
|
||||
"class-validator": "^0.12.2",
|
||||
"pg": "^8.4.2",
|
||||
"reflect-metadata": "^0.1.10",
|
||||
|
|
29
src/index.ts
29
src/index.ts
|
@ -1,9 +1,10 @@
|
|||
import "reflect-metadata";
|
||||
import {createConnection} from "typeorm";
|
||||
import {Address} from "./entity/Address";
|
||||
import { Server, Request, ResponseToolkit } from "@hapi/hapi";
|
||||
|
||||
createConnection().then(async connection => {
|
||||
|
||||
const init = async () => {
|
||||
const connection = await createConnection();
|
||||
console.log("Inserting a new user into the database...");
|
||||
const addr = new Address();
|
||||
addr.street = "Test";
|
||||
|
@ -15,8 +16,22 @@ createConnection().then(async connection => {
|
|||
await connection.manager.save(addr);
|
||||
console.log("Saved a new addr with id: " + addr.id);
|
||||
|
||||
console.log("Loading addr from the database...");
|
||||
const addrs = await connection.manager.find(Address);
|
||||
console.log("Loaded addr: ", addrs);
|
||||
|
||||
}).catch(error => console.log(error));
|
||||
const server: Server = new Server({
|
||||
port: 3000,
|
||||
host: 'localhost'
|
||||
});
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/',
|
||||
handler: (request: Request, h: ResponseToolkit) => {
|
||||
return connection.manager.find(Address);
|
||||
}
|
||||
});
|
||||
await server.start();
|
||||
console.log('Server running on %s', server.info.uri);
|
||||
};
|
||||
process.on('unhandledRejection', (err) => {
|
||||
console.log(err);
|
||||
process.exit(1);
|
||||
});
|
||||
init();
|
Reference in New Issue