diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-02-07 14:22:08 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-02-07 14:22:08 +0200 |
| commit | 7a0f65385189cc6e888027d5f286794e07a6fe2a (patch) | |
| tree | eb523e6a2faf2685a653fb0ada622706c5a68e5b /src | |
Initial commit
Diffstat (limited to 'src')
| -rw-r--r-- | src/index.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..dac8807 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,31 @@ +import { App } from "@tinyhttp/app" +import { logger } from "@tinyhttp/logger" +import pg from "pg" +import { ExampleApi } from "slam-types" + +const client = new pg.Client({ + user: process.env.PGUSER ?? "postgres", + host: process.env.PGHOST ?? "localhost", + database: process.env.PGDATABASE ?? "postgres", + password: process.env.PGPASSWORD ?? "postgres", + port: process.env.PGPORT ? Number(process.env.PGPORT) : 5432, +}) + +client.connect() + +const app = new App() + +const PORT = Number(process.env.PORT) || 3000 +console.log(`Serving API on port ${PORT}`) + +app + .use(logger({ + timestamp: { format: "YYYY-MM-DDTHH:mm:ssZ" }, + })) + .get(ExampleApi.ListRequest.path, async (_req, res) => { + const response: ExampleApi.ListResponse.Body = { + examples: [{ id: "123", title: "foobar", content: "10 20 + ." }], + } + res.send(response) + }) + .listen(PORT) |
