37 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import "reflect-metadata";
 | |
| import {createConnection} from "typeorm";
 | |
| import {Address} from "./entity/Address";
 | |
| import { Server, Request, ResponseToolkit } from "@hapi/hapi";
 | |
| 
 | |
| const init = async () => {
 | |
|     const connection = await createConnection();
 | |
|     console.log("Inserting a new user into the database...");
 | |
|     const addr = new Address();
 | |
|     addr.street = "Test";
 | |
|     addr.number = "1";
 | |
|     addr.city = "herzo";
 | |
|     addr.plz = "91074";
 | |
|     addr.state = "Franken";
 | |
|     addr.country = "Germany"
 | |
|     await connection.manager.save(addr);
 | |
|     console.log("Saved a new addr with id: " + addr.id);
 | |
| 
 | |
|     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(); |