initial code commit

This commit is contained in:
Lio Young 2021-04-12 23:34:44 +02:00
parent 371e84427e
commit 5db5b2321b
No known key found for this signature in database
GPG Key ID: 789795A11879E169
2 changed files with 51 additions and 0 deletions

View File

@ -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<Shorten>("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<Shorten>("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;

5
src/types.ts Normal file
View File

@ -0,0 +1,5 @@
export type Shorten = {
id: number
url: string
slug: string
}