Added config object
This commit is contained in:
parent
68b9b43891
commit
7cfcb54195
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue