From 5db5b2321bd3cb3e3dc9a3217e3fe106b8d69eea Mon Sep 17 00:00:00 2001 From: Lio Young Date: Mon, 12 Apr 2021 23:34:44 +0200 Subject: [PATCH] initial code commit --- index.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/types.ts | 5 +++++ 2 files changed, 51 insertions(+) create mode 100644 src/types.ts diff --git a/index.ts b/index.ts index e69de29..f5be057 100644 --- a/index.ts +++ b/index.ts @@ -0,0 +1,46 @@ +import express from "express"; +import helmet from "helmet"; +import { createClient } from "@supabase/supabase-js"; +import { Shorten } from "./src/types"; + +const app = express(); +// @ts-ignore +const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY) + + +app.use(express.json({ limit: '50mb' })); +app.use(express.urlencoded({ extended: true, limit: '50mb' })); +app.use(helmet()); + + +app.get("/", async (req, res) => { + let { data, error } = await supabase.from("brevis").select() + if (error) return res.status(400).json(error) + + console.log(data) + + return res.json({ + data + }) +}) + +app.get("/:slug", async (req, res) => { + let { data, error } = await supabase.from("brevis").select() + if (error) return res.status(400).json(error) + + return res.json({ + data: data + }) +}) + + +// default catch all handler +app.all('*', (req, res) => { + res.status(404).json({ + success: false, + message: 'route not defined', + data: null, + }); +}); + +module.exports = app; \ No newline at end of file diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..e375306 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,5 @@ +export type Shorten = { + id: number + url: string + slug: string +} \ No newline at end of file