Added config object

This commit is contained in:
Nicolai Ort 2021-08-12 20:24:26 +02:00
parent 68b9b43891
commit 7cfcb54195
Signed by: niggl
GPG Key ID: 13AFA55AF62F269F
1 changed files with 13 additions and 2 deletions

View File

@ -1,6 +1,17 @@
const fastify = require('fastify')({ logger: true })
var uniqid = require('uniqid');
let config = {
domain: process.env.DOMAIN || "localhost:3000",
https: false,
getBaseUrl(){
if(config.https){
return `https://${config.domain}`;
}
return `http://${config.domain}`;
}
}
const knex = require('knex')({
client: 'sqlite3',
connection: {
@ -66,7 +77,7 @@ fastify.post('/new', { newUrlSchema }, async (req, res) => {
if (exists.length != 0) {
shortcode = exists[0].shortcode;
return {
url: `http://localhost:3000/${shortcode}`,
url: `${config.getBaseUrl()}/${shortcode}`,
shortcode,
target
}
@ -86,7 +97,7 @@ fastify.post('/new', { newUrlSchema }, async (req, res) => {
await knex('urls').insert({target, shortcode});
return {
url: `http://localhost:3000${shortcode}`,
url: `${config.getBaseUrl()}/${shortcode}`,
shortcode,
target
}