functional initial commit
This commit is contained in:
commit
35faea37cc
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.env
|
51
api.ts
Normal file
51
api.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import { Application, Router } from 'https://deno.land/x/oak/mod.ts';
|
||||||
|
import { Client } from "https://deno.land/x/postgres@v0.17.0/mod.ts";
|
||||||
|
|
||||||
|
const app = new Application();
|
||||||
|
const router = new Router();
|
||||||
|
|
||||||
|
//---------dotenv info-------------
|
||||||
|
import { load } from "https://deno.land/std/dotenv/mod.ts";
|
||||||
|
|
||||||
|
const env = await load();
|
||||||
|
const hostname = env["HOSTNAME"];
|
||||||
|
const port = env["PORT"];
|
||||||
|
const user = env["USER"];
|
||||||
|
const password = env["PASSWORD"];
|
||||||
|
const database = env["DATABASE"];
|
||||||
|
const app_port = env["APP_PORT"];
|
||||||
|
|
||||||
|
console.log(password);
|
||||||
|
// "Geheimnis"
|
||||||
|
//---------------------------------
|
||||||
|
|
||||||
|
// Configure database connection
|
||||||
|
const client = new Client({
|
||||||
|
hostname:hostname
|
||||||
|
,port: port
|
||||||
|
,user: user
|
||||||
|
,password:password
|
||||||
|
,database:database
|
||||||
|
});
|
||||||
|
|
||||||
|
await client.connect();
|
||||||
|
|
||||||
|
// Define a route to retrieve values from the database
|
||||||
|
router.get('/', async (ctx) => {
|
||||||
|
ctx.response.body = "live";
|
||||||
|
});
|
||||||
|
// Define a route to retrieve values from the database
|
||||||
|
router.get('/api/data', async (ctx) => {
|
||||||
|
const result = await client.queryObject("SELECT * FROM rlarp.pl LIMIT 10");
|
||||||
|
console.log(result.rows); // [{id: 1, name: 'Carlos'}, {id: 2, name: 'Johnru'}, ...]
|
||||||
|
//const result = await client.query('SELECT 1');
|
||||||
|
ctx.response.body = result.rows;
|
||||||
|
});
|
||||||
|
|
||||||
|
app.use(router.routes());
|
||||||
|
app.use(router.allowedMethods());
|
||||||
|
|
||||||
|
// Start the server
|
||||||
|
console.log('Server is running on http://localhost:8085');
|
||||||
|
await app.listen({ port: 8085 });
|
||||||
|
|
Loading…
Reference in New Issue
Block a user