Added leveldb
This commit is contained in:
		@@ -4,7 +4,6 @@
 | 
			
		||||
  "main": "index.js",
 | 
			
		||||
  "license": "MIT",
 | 
			
		||||
  "private": false,
 | 
			
		||||
  "type": "module",
 | 
			
		||||
  "scripts": {
 | 
			
		||||
    "dev": "nodemon src/server.js",
 | 
			
		||||
    "start": "node src/server.js"
 | 
			
		||||
@@ -12,6 +11,7 @@
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "fastify": "^3.20.1",
 | 
			
		||||
    "knex": "^0.21.21",
 | 
			
		||||
    "level": "^7.0.0",
 | 
			
		||||
    "sqlite3": "^5.0.2"
 | 
			
		||||
  },
 | 
			
		||||
  "devDependencies": {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,19 +1,32 @@
 | 
			
		||||
const fastify = require('fastify')({ logger: true })
 | 
			
		||||
const level = require('level')
 | 
			
		||||
 | 
			
		||||
const db = level('./db', { valueEncoding: 'json' })
 | 
			
		||||
 | 
			
		||||
// Declare a route
 | 
			
		||||
fastify.get('/', async (request, reply) => {
 | 
			
		||||
    return { hello: 'world' }
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
//Automagic Amazn redirects on /a/
 | 
			
		||||
fastify.get('/a/:id', async (req, res) => {
 | 
			
		||||
    res.redirect(302, `https://amazon.de/dp/${req.params.id}`)
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
fastify.get('/:id', async (req, res)=>{
 | 
			
		||||
    res.statusCode = 301;
 | 
			
		||||
    return req.params.id;
 | 
			
		||||
//Automagic Youtube redirects on /yt/
 | 
			
		||||
fastify.get('/yt/:id', async (req, res) => {
 | 
			
		||||
    res.redirect(302, `https://youtu.be/${req.params.id}`)
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
fastify.get('/:id', async (req, res) => {
 | 
			
		||||
    try {
 | 
			
		||||
        const target = await db.get(req.params.id);
 | 
			
		||||
        res.redirect(302, target);
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
        res.statusCode = 404;
 | 
			
		||||
        return 404;
 | 
			
		||||
    }
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
fastify.post('/new', async (req, res) => {
 | 
			
		||||
    console.log(req.body);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user