Compare commits
	
		
			11 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 86f4cd00ea | |||
| 
						
						
							
						
						518aa3eb08
	
				 | 
					
					
						|||
| 86985ef735 | |||
| 
						
						
							
						
						fef7daaf96
	
				 | 
					
					
						|||
| b14fa05adc | |||
| 
						
						
							
						
						7c71e94304
	
				 | 
					
					
						|||
| 
						
						
							
						
						8fa489f2bc
	
				 | 
					
					
						|||
| 
						
						
							
						
						512acc0b8c
	
				 | 
					
					
						|||
| 567ac07612 | |||
| 
						
						
							
						
						fa01864d0d
	
				 | 
					
					
						|||
| 
						
						
							
						
						91b25c22ca
	
				 | 
					
					
						
							
								
								
									
										3
									
								
								.env
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								.env
									
									
									
									
									
								
							@@ -1,3 +1,4 @@
 | 
			
		||||
SSL=false
 | 
			
		||||
SSL=true
 | 
			
		||||
DOMAIN=kauft.es
 | 
			
		||||
DISABLE_PROVIDERS=false
 | 
			
		||||
ENABLE_REGISTER=true
 | 
			
		||||
							
								
								
									
										25
									
								
								CHANGELOG.md
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								CHANGELOG.md
									
									
									
									
									
								
							@@ -2,8 +2,33 @@
 | 
			
		||||
 | 
			
		||||
All notable changes to this project will be documented in this file. Dates are displayed in UTC.
 | 
			
		||||
 | 
			
		||||
#### [0.1.4](https://git.odit.services/kauft.es/linkylinky/compare/0.1.3...0.1.4)
 | 
			
		||||
 | 
			
		||||
- Added cors [`518aa3e`](https://git.odit.services/kauft.es/linkylinky/commit/518aa3eb08cb72854812130d45b3b89afb074693)
 | 
			
		||||
 | 
			
		||||
#### [0.1.3](https://git.odit.services/kauft.es/linkylinky/compare/0.1.2...0.1.3)
 | 
			
		||||
 | 
			
		||||
> 14 August 2021
 | 
			
		||||
 | 
			
		||||
- Weired knex env fix [`fef7daa`](https://git.odit.services/kauft.es/linkylinky/commit/fef7daaf961e9112aa00f2ad22c3b0518ad258a7)
 | 
			
		||||
- 🚀RELEASE 0.1.3 [`86985ef`](https://git.odit.services/kauft.es/linkylinky/commit/86985ef7355c2db09dcd6c8e52ee7ebde3ed4128)
 | 
			
		||||
 | 
			
		||||
#### [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)
 | 
			
		||||
 | 
			
		||||
> 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)
 | 
			
		||||
 | 
			
		||||
#### [0.1.0](https://git.odit.services/kauft.es/linkylinky/compare/0.0.2...0.1.0)
 | 
			
		||||
 
 | 
			
		||||
@@ -4,8 +4,9 @@ COPY package.json .
 | 
			
		||||
COPY yarn.lock .
 | 
			
		||||
RUN yarn --production --frozen-lockfile
 | 
			
		||||
COPY migrations ./migrations
 | 
			
		||||
COPY src/server.js ./
 | 
			
		||||
COPY src ./src
 | 
			
		||||
COPY knexfile.js ./
 | 
			
		||||
RUN mkdir db
 | 
			
		||||
# 
 | 
			
		||||
# FROM astefanutti/scratch-node:16.0.0
 | 
			
		||||
FROM node:16.6.2-alpine3.14
 | 
			
		||||
@@ -13,4 +14,4 @@ WORKDIR /app
 | 
			
		||||
COPY --from=0 /app /app
 | 
			
		||||
ENV NODE_ENV production
 | 
			
		||||
EXPOSE 3000
 | 
			
		||||
ENTRYPOINT ["node", "./server.js"]
 | 
			
		||||
ENTRYPOINT ["/bin/sh", "-c", "yarn migrate && node ./src/server.js"]
 | 
			
		||||
@@ -5,3 +5,5 @@ services:
 | 
			
		||||
    #image: registry.odit.services/kauft.es/linkylinky:latest
 | 
			
		||||
    ports:
 | 
			
		||||
      - 3000:3000
 | 
			
		||||
    #volumes:
 | 
			
		||||
    #  - ./db:/app/db
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ module.exports = {
 | 
			
		||||
  production: {
 | 
			
		||||
    client: 'sqlite3',
 | 
			
		||||
    connection: {
 | 
			
		||||
      filename: './db.sqlite3'
 | 
			
		||||
      filename: './db/db.sqlite3'
 | 
			
		||||
    },
 | 
			
		||||
    migrations: {
 | 
			
		||||
      tableName: 'knex_migrations'
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "@odit/shortener-backend",
 | 
			
		||||
  "version": "0.1.1",
 | 
			
		||||
  "version": "0.1.4",
 | 
			
		||||
  "main": "index.js",
 | 
			
		||||
  "license": "MIT",
 | 
			
		||||
  "private": false,
 | 
			
		||||
@@ -15,6 +15,7 @@
 | 
			
		||||
    "dotenv": "^10.0.0",
 | 
			
		||||
    "fastify": "^3.20.1",
 | 
			
		||||
    "fastify-basic-auth": "^2.1.0",
 | 
			
		||||
    "fastify-cors": "^6.0.2",
 | 
			
		||||
    "knex": "^0.21.21",
 | 
			
		||||
    "sqlite3": "^5.0.2",
 | 
			
		||||
    "uniqid": "^5.3.0"
 | 
			
		||||
 
 | 
			
		||||
@@ -15,16 +15,17 @@ let config = {
 | 
			
		||||
        return `http://${config.domain}`;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const knex = require('knex')({
 | 
			
		||||
    client: 'sqlite3',
 | 
			
		||||
    connection: {
 | 
			
		||||
        filename: "./dev.sqlite3"
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
const environment = process.env.NODE_ENV || 'development';
 | 
			
		||||
const knexConfiguration = require('../knexfile')[environment];
 | 
			
		||||
const knex = require('knex')(knexConfiguration);
 | 
			
		||||
 | 
			
		||||
const authenticate = { realm: 'Short' }
 | 
			
		||||
fastify.register(require('fastify-basic-auth'), { validate, authenticate });
 | 
			
		||||
fastify.register(require('fastify-cors'), { 
 | 
			
		||||
    origin: true,
 | 
			
		||||
    preflight: true,
 | 
			
		||||
    preflightContinue: true
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
//Automagic Amazn redirects on /a/
 | 
			
		||||
fastify.get('/a/:id', async (req, res) => {
 | 
			
		||||
@@ -221,7 +222,7 @@ fastify.after(() => {
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    //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;
 | 
			
		||||
 | 
			
		||||
        //This should never happen but better safe than 500
 | 
			
		||||
@@ -237,6 +238,23 @@ fastify.after(() => {
 | 
			
		||||
        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 +316,6 @@ async function validate(username, password, req, reply) {
 | 
			
		||||
 | 
			
		||||
// Run the server!
 | 
			
		||||
const start = async () => {
 | 
			
		||||
    try {
 | 
			
		||||
        await knex.migrate.latest()
 | 
			
		||||
    } catch (err) {
 | 
			
		||||
        fastify.log.error(err)
 | 
			
		||||
        process.exit(1)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
        await fastify.listen(3000, '0.0.0.0')
 | 
			
		||||
    } catch (err) {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										13
									
								
								yarn.lock
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								yarn.lock
									
									
									
									
									
								
							@@ -1249,6 +1249,14 @@ fastify-basic-auth@^2.1.0:
 | 
			
		||||
    fastify-plugin "^3.0.0"
 | 
			
		||||
    http-errors "^1.7.3"
 | 
			
		||||
 | 
			
		||||
fastify-cors@^6.0.2:
 | 
			
		||||
  version "6.0.2"
 | 
			
		||||
  resolved "https://registry.yarnpkg.com/fastify-cors/-/fastify-cors-6.0.2.tgz#4fd5102549659e9b34d252fd7ee607b63d021390"
 | 
			
		||||
  integrity sha512-sE0AOyzmj5hLLRRVgenjA6G2iOGX35/1S3QGYB9rr9TXelMZB3lFrXy4CzwYVOMiujJeMiLgO4J7eRm8sQSv8Q==
 | 
			
		||||
  dependencies:
 | 
			
		||||
    fastify-plugin "^3.0.0"
 | 
			
		||||
    vary "^1.1.2"
 | 
			
		||||
 | 
			
		||||
fastify-error@^0.3.0:
 | 
			
		||||
  version "0.3.1"
 | 
			
		||||
  resolved "https://registry.yarnpkg.com/fastify-error/-/fastify-error-0.3.1.tgz#8eb993e15e3cf57f0357fc452af9290f1c1278d2"
 | 
			
		||||
@@ -4014,6 +4022,11 @@ v8flags@^3.2.0:
 | 
			
		||||
  dependencies:
 | 
			
		||||
    homedir-polyfill "^1.0.1"
 | 
			
		||||
 | 
			
		||||
vary@^1.1.2:
 | 
			
		||||
  version "1.1.2"
 | 
			
		||||
  resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
 | 
			
		||||
  integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=
 | 
			
		||||
 | 
			
		||||
verror@1.10.0:
 | 
			
		||||
  version "1.10.0"
 | 
			
		||||
  resolved "https://registry.yarnpkg.com/verror/-/verror-1.10.0.tgz#3a105ca17053af55d6e270c1f8288682e18da400"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user