9 Commits
0.1.1 ... 0.1.3

Author SHA1 Message Date
86985ef735 🚀RELEASE 0.1.3
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-14 13:23:38 +02:00
fef7daaf96 Weired knex env fix 2021-08-14 13:23:11 +02:00
b14fa05adc 🚀RELEASE 0.1.2
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-14 13:10:00 +02:00
7c71e94304 Added optional db volume to docker-compose 2021-08-14 13:09:40 +02:00
8fa489f2bc Changed the way that the migration get's triggered 2021-08-14 13:09:25 +02:00
512acc0b8c Prod db now resides in db folder
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-14 12:56:02 +02:00
567ac07612 Merge branch 'main' of git.odit.services:kauft.es/linkylinky into main
All checks were successful
continuous-integration/drone/push Build is passing
2021-08-14 11:50:35 +02:00
fa01864d0d API Endpoint to get all short urls 2021-08-14 11:50:29 +02:00
91b25c22ca Get all api endpoints 2021-08-14 11:50:03 +02:00
7 changed files with 48 additions and 20 deletions

3
.env
View File

@@ -1,3 +1,4 @@
SSL=false SSL=true
DOMAIN=kauft.es
DISABLE_PROVIDERS=false DISABLE_PROVIDERS=false
ENABLE_REGISTER=true ENABLE_REGISTER=true

View File

@@ -2,8 +2,26 @@
All notable changes to this project will be documented in this file. Dates are displayed in UTC. All notable changes to this project will be documented in this file. Dates are displayed in UTC.
#### [0.1.3](https://git.odit.services/kauft.es/linkylinky/compare/0.1.2...0.1.3)
- Weired knex env fix [`fef7daa`](https://git.odit.services/kauft.es/linkylinky/commit/fef7daaf961e9112aa00f2ad22c3b0518ad258a7)
#### [0.1.2](https://git.odit.services/kauft.es/linkylinky/compare/0.1.1...0.1.2)
> 14 August 2021
- API Endpoint to get all short urls [`fa01864`](https://git.odit.services/kauft.es/linkylinky/commit/fa01864d0de7921e741d63c3f5795161279ea478)
- 🚀RELEASE 0.1.2 [`b14fa05`](https://git.odit.services/kauft.es/linkylinky/commit/b14fa05adc1ef8e34fd73bf5f495505df7d44b33)
- Changed the way that the migration get's triggered [`8fa489f`](https://git.odit.services/kauft.es/linkylinky/commit/8fa489f2bcd9d1ad63ab4581b7f3b27eee3d9038)
- Get all api endpoints [`91b25c2`](https://git.odit.services/kauft.es/linkylinky/commit/91b25c22ca035aec5cc2fdc80ca4fbb56a2f8b65)
- Added optional db volume to docker-compose [`7c71e94`](https://git.odit.services/kauft.es/linkylinky/commit/7c71e943041d8e3ac9dcf95cad27f2f0bc0b024c)
- Prod db now resides in db folder [`512acc0`](https://git.odit.services/kauft.es/linkylinky/commit/512acc0b8c15d4cfbafef21ec20707bac4629ea4)
#### [0.1.1](https://git.odit.services/kauft.es/linkylinky/compare/0.1.0...0.1.1) #### [0.1.1](https://git.odit.services/kauft.es/linkylinky/compare/0.1.0...0.1.1)
> 14 August 2021
- 🚀RELEASE 0.1.1 [`55d6b91`](https://git.odit.services/kauft.es/linkylinky/commit/55d6b91cc252ee6676d13df9abd8b61283a07f0f)
- fix: Dockerfile [`807eb9c`](https://git.odit.services/kauft.es/linkylinky/commit/807eb9c267377df0b5f30f81eb380ef8a1c2add2) - fix: Dockerfile [`807eb9c`](https://git.odit.services/kauft.es/linkylinky/commit/807eb9c267377df0b5f30f81eb380ef8a1c2add2)
#### [0.1.0](https://git.odit.services/kauft.es/linkylinky/compare/0.0.2...0.1.0) #### [0.1.0](https://git.odit.services/kauft.es/linkylinky/compare/0.0.2...0.1.0)

View File

@@ -4,8 +4,9 @@ COPY package.json .
COPY yarn.lock . COPY yarn.lock .
RUN yarn --production --frozen-lockfile RUN yarn --production --frozen-lockfile
COPY migrations ./migrations COPY migrations ./migrations
COPY src/server.js ./ COPY src ./src
COPY knexfile.js ./ COPY knexfile.js ./
RUN mkdir db
# #
# FROM astefanutti/scratch-node:16.0.0 # FROM astefanutti/scratch-node:16.0.0
FROM node:16.6.2-alpine3.14 FROM node:16.6.2-alpine3.14
@@ -13,4 +14,4 @@ WORKDIR /app
COPY --from=0 /app /app COPY --from=0 /app /app
ENV NODE_ENV production ENV NODE_ENV production
EXPOSE 3000 EXPOSE 3000
ENTRYPOINT ["node", "./server.js"] ENTRYPOINT ["/bin/sh", "-c", "yarn migrate && node ./src/server.js"]

View File

@@ -5,3 +5,5 @@ services:
#image: registry.odit.services/kauft.es/linkylinky:latest #image: registry.odit.services/kauft.es/linkylinky:latest
ports: ports:
- 3000:3000 - 3000:3000
#volumes:
# - ./db:/app/db

View File

@@ -12,7 +12,7 @@ module.exports = {
production: { production: {
client: 'sqlite3', client: 'sqlite3',
connection: { connection: {
filename: './db.sqlite3' filename: './db/db.sqlite3'
}, },
migrations: { migrations: {
tableName: 'knex_migrations' tableName: 'knex_migrations'

View File

@@ -1,6 +1,6 @@
{ {
"name": "@odit/shortener-backend", "name": "@odit/shortener-backend",
"version": "0.1.1", "version": "0.1.3",
"main": "index.js", "main": "index.js",
"license": "MIT", "license": "MIT",
"private": false, "private": false,

View File

@@ -15,13 +15,9 @@ let config = {
return `http://${config.domain}`; return `http://${config.domain}`;
} }
} }
const environment = process.env.NODE_ENV || 'development';
const knex = require('knex')({ const knexConfiguration = require('../knexfile')[environment];
client: 'sqlite3', const knex = require('knex')(knexConfiguration);
connection: {
filename: "./dev.sqlite3"
}
});
const authenticate = { realm: 'Short' } const authenticate = { realm: 'Short' }
fastify.register(require('fastify-basic-auth'), { validate, authenticate }); fastify.register(require('fastify-basic-auth'), { validate, authenticate });
@@ -221,7 +217,7 @@ fastify.after(() => {
}); });
//Get url api route //Get url api route
fastify.delete('/api/:shortcode', async (req, res) => { fastify.delete('/api/:shortcode', { onRequest: fastify.basicAuth }, async (req, res) => {
const shortcode = req.params.shortcode; const shortcode = req.params.shortcode;
//This should never happen but better safe than 500 //This should never happen but better safe than 500
@@ -237,6 +233,23 @@ fastify.after(() => {
return true; return true;
}); });
//Get all urls api route
fastify.get('/api', { onRequest: fastify.basicAuth }, async (req, res) => {
urls = await knex.select('target', 'shortcode')
.from('urls');
for (let url of urls) {
url.url = `${config.getBaseUrl()}/${url.shortcode}`
if(req.query.showVisits){
url.visits = (await knex.select('timestamp')
.from('visits')
.where('shortcode', '=', url.shortcode)).length;
}
}
return urls;
});
}); });
@@ -298,13 +311,6 @@ async function validate(username, password, req, reply) {
// Run the server! // Run the server!
const start = async () => { const start = async () => {
try {
await knex.migrate.latest()
} catch (err) {
fastify.log.error(err)
process.exit(1)
}
try { try {
await fastify.listen(3000, '0.0.0.0') await fastify.listen(3000, '0.0.0.0')
} catch (err) { } catch (err) {