Compare commits
	
		
			24 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 72932955d1 | |||
| 339e2f39d8 | |||
| 12c6d7e3da | |||
| 1624e666e8 | |||
| 86f4cd00ea | |||
| 518aa3eb08 | |||
| 86985ef735 | |||
| fef7daaf96 | |||
| b14fa05adc | |||
| 7c71e94304 | |||
| 8fa489f2bc | |||
| 512acc0b8c | |||
| 567ac07612 | |||
| fa01864d0d | |||
| 91b25c22ca | |||
| 55d6b91cc2 | |||
| 807eb9c267 | |||
| e02d91e662 | |||
| 8d9cf8d1b3 | |||
| d97450cf53 | |||
| fd0a586ed6 | |||
| af6500ccb4 | |||
| 9a3c55d235 | |||
| 86ef277c90 | 
							
								
								
									
										3
									
								
								.env
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								.env
									
									
									
									
									
								
							| @@ -1,3 +1,4 @@ | |||||||
| SSL=false | SSL=true | ||||||
|  | DOMAIN=kauft.es | ||||||
| DISABLE_PROVIDERS=false | DISABLE_PROVIDERS=false | ||||||
| ENABLE_REGISTER=true | ENABLE_REGISTER=true | ||||||
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -58,7 +58,6 @@ jspm_packages/ | |||||||
| .yarn/build-state.yml | .yarn/build-state.yml | ||||||
| .yarn/install-state.gz | .yarn/install-state.gz | ||||||
| .pnp.* | .pnp.* | ||||||
| yarn.lock |  | ||||||
| package-lock.json | package-lock.json | ||||||
|  |  | ||||||
| *.sqlite* | *.sqlite* | ||||||
							
								
								
									
										51
									
								
								CHANGELOG.md
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								CHANGELOG.md
									
									
									
									
									
								
							| @@ -2,11 +2,62 @@ | |||||||
|  |  | ||||||
| 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.2.0](https://git.odit.services/kauft.es/linkylinky/compare/0.1.4...0.2.0) | ||||||
|  |  | ||||||
|  | - Added ebay provider recognition [`12c6d7e`](https://git.odit.services/kauft.es/linkylinky/commit/12c6d7e3da5cb4de6a597b4639f313b8e4319646) | ||||||
|  | - Ebay provider resolution [`339e2f3`](https://git.odit.services/kauft.es/linkylinky/commit/339e2f39d88d42a961e1e495f319dc0663cdc0a6) | ||||||
|  | - Now recognizing with and without protocol [`1624e66`](https://git.odit.services/kauft.es/linkylinky/commit/1624e666e83e0afe346bcacb105ea1a1535f0690) | ||||||
|  |  | ||||||
|  | #### [0.1.4](https://git.odit.services/kauft.es/linkylinky/compare/0.1.3...0.1.4) | ||||||
|  |  | ||||||
|  | > 14 August 2021 | ||||||
|  |  | ||||||
|  | - Added cors [`518aa3e`](https://git.odit.services/kauft.es/linkylinky/commit/518aa3eb08cb72854812130d45b3b89afb074693) | ||||||
|  | - 🚀RELEASE 0.1.4 [`86f4cd0`](https://git.odit.services/kauft.es/linkylinky/commit/86f4cd00ea517f7e2cacbf69f2163eae597610ee) | ||||||
|  |  | ||||||
|  | #### [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) | ||||||
|  |  | ||||||
|  | > 14 August 2021 | ||||||
|  |  | ||||||
|  | - add lockfile [skip-ci] [`d97450c`](https://git.odit.services/kauft.es/linkylinky/commit/d97450cf5389965d8183b5719aad7e9e6f0181ae) | ||||||
|  | - 🚀RELEASE 0.1.0 [`e02d91e`](https://git.odit.services/kauft.es/linkylinky/commit/e02d91e662e090b79b03ec77896100923464aa6b) | ||||||
|  | - smaller Dockerfile [skip-ci] [`86ef277`](https://git.odit.services/kauft.es/linkylinky/commit/86ef277c902aabb52acb5f846cb55406dc4d1095) | ||||||
|  | - Added tag commit args [`fd0a586`](https://git.odit.services/kauft.es/linkylinky/commit/fd0a586ed6e365801979c16d809a8254f64049be) | ||||||
|  | - Now signing release commits [`af6500c`](https://git.odit.services/kauft.es/linkylinky/commit/af6500ccb4792616f28bec77eda5c5e116422604) | ||||||
|  |  | ||||||
| #### 0.0.2 | #### 0.0.2 | ||||||
|  |  | ||||||
|  | > 14 August 2021 | ||||||
|  |  | ||||||
| - Migrated to knex [`823b211`](https://git.odit.services/kauft.es/linkylinky/commit/823b211c8c4fd4de3a6043696ca070101173aa1b) | - Migrated to knex [`823b211`](https://git.odit.services/kauft.es/linkylinky/commit/823b211c8c4fd4de3a6043696ca070101173aa1b) | ||||||
| - Added basics for auth [`6d417fa`](https://git.odit.services/kauft.es/linkylinky/commit/6d417fac1b4d77ab5552b75483cfc787d466e699) | - Added basics for auth [`6d417fa`](https://git.odit.services/kauft.es/linkylinky/commit/6d417fac1b4d77ab5552b75483cfc787d466e699) | ||||||
| - Initial [`ab17f91`](https://git.odit.services/kauft.es/linkylinky/commit/ab17f9148af6811a53bf323172d045cc71ecfb6d) | - Initial [`ab17f91`](https://git.odit.services/kauft.es/linkylinky/commit/ab17f9148af6811a53bf323172d045cc71ecfb6d) | ||||||
|  | - 🚀RELEASE 0.0.2 [`a4bdb4d`](https://git.odit.services/kauft.es/linkylinky/commit/a4bdb4dca4aaba397688d43f1ec3a26cb2143dea) | ||||||
| - Added image builds by drone [`1a8410c`](https://git.odit.services/kauft.es/linkylinky/commit/1a8410c421e30001ae9623c19a8e72e0632ed920) | - Added image builds by drone [`1a8410c`](https://git.odit.services/kauft.es/linkylinky/commit/1a8410c421e30001ae9623c19a8e72e0632ed920) | ||||||
| - Working registration/auth [`81b314a`](https://git.odit.services/kauft.es/linkylinky/commit/81b314ac55e9ab0cd603dda48473c0fe3db6c42e) | - Working registration/auth [`81b314a`](https://git.odit.services/kauft.es/linkylinky/commit/81b314ac55e9ab0cd603dda48473c0fe3db6c42e) | ||||||
| - Implemented short code generation via nanoid [`1550860`](https://git.odit.services/kauft.es/linkylinky/commit/15508606a41057857cce0d2ae16e389432c76960) | - Implemented short code generation via nanoid [`1550860`](https://git.odit.services/kauft.es/linkylinky/commit/15508606a41057857cce0d2ae16e389432c76960) | ||||||
|   | |||||||
							
								
								
									
										26
									
								
								Dockerfile
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								Dockerfile
									
									
									
									
									
								
							| @@ -1,15 +1,17 @@ | |||||||
| FROM node:16-alpine as run | FROM node:16.6.2-alpine3.14 | ||||||
|  | WORKDIR /app | ||||||
| COPY package.json . | COPY package.json . | ||||||
| RUN yarn --prod | COPY yarn.lock . | ||||||
|  | RUN yarn --production --frozen-lockfile | ||||||
|  | COPY migrations ./migrations | ||||||
|  | COPY src ./src | ||||||
|  | COPY knexfile.js ./ | ||||||
|  | RUN mkdir db | ||||||
|  | #  | ||||||
|  | # FROM astefanutti/scratch-node:16.0.0 | ||||||
|  | FROM node:16.6.2-alpine3.14 | ||||||
|  | WORKDIR /app | ||||||
|  | COPY --from=0 /app /app | ||||||
| ENV NODE_ENV production | ENV NODE_ENV production | ||||||
| EXPOSE 3000 | EXPOSE 3000 | ||||||
|  | ENTRYPOINT ["/bin/sh", "-c", "yarn migrate && node ./src/server.js"] | ||||||
| WORKDIR /app |  | ||||||
|  |  | ||||||
| COPY migrations ./migrations |  | ||||||
| COPY src/server.js ./ |  | ||||||
| COPY knexfile.js ./ |  | ||||||
|  |  | ||||||
| CMD ["node", "./server.js"] |  | ||||||
| @@ -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 | ||||||
|   | |||||||
| @@ -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' | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "@odit/shortener-backend", |   "name": "@odit/shortener-backend", | ||||||
|   "version": "0.0.2", |   "version": "0.2.0", | ||||||
|   "main": "index.js", |   "main": "index.js", | ||||||
|   "license": "MIT", |   "license": "MIT", | ||||||
|   "private": false, |   "private": false, | ||||||
| @@ -15,6 +15,7 @@ | |||||||
|     "dotenv": "^10.0.0", |     "dotenv": "^10.0.0", | ||||||
|     "fastify": "^3.20.1", |     "fastify": "^3.20.1", | ||||||
|     "fastify-basic-auth": "^2.1.0", |     "fastify-basic-auth": "^2.1.0", | ||||||
|  |     "fastify-cors": "^6.0.2", | ||||||
|     "knex": "^0.21.21", |     "knex": "^0.21.21", | ||||||
|     "sqlite3": "^5.0.2", |     "sqlite3": "^5.0.2", | ||||||
|     "uniqid": "^5.3.0" |     "uniqid": "^5.3.0" | ||||||
| @@ -28,6 +29,12 @@ | |||||||
|       "commit": true, |       "commit": true, | ||||||
|       "requireCleanWorkingDir": false, |       "requireCleanWorkingDir": false, | ||||||
|       "commitMessage": "🚀RELEASE ${version}", |       "commitMessage": "🚀RELEASE ${version}", | ||||||
|  |       "git.commitArgs": [ | ||||||
|  |         "-S" | ||||||
|  |       ], | ||||||
|  |       "git.tagArgs": [ | ||||||
|  |         "-S" | ||||||
|  |       ], | ||||||
|       "push": true, |       "push": true, | ||||||
|       "tag": true, |       "tag": true, | ||||||
|       "tagName": null, |       "tagName": null, | ||||||
|   | |||||||
| @@ -15,16 +15,17 @@ 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 }); | ||||||
|  | fastify.register(require('fastify-cors'), {  | ||||||
|  |     origin: true, | ||||||
|  |     preflight: true, | ||||||
|  |     preflightContinue: true | ||||||
|  |   }) | ||||||
|  |  | ||||||
| //Automagic Amazn redirects on /a/ | //Automagic Amazn redirects on /a/ | ||||||
| fastify.get('/a/:id', async (req, res) => { | fastify.get('/a/:id', async (req, res) => { | ||||||
| @@ -40,6 +41,11 @@ fastify.get('/ytpl/:id', async (req, res) => { | |||||||
|     res.redirect(302, `https://youtube.com/playlist?list=${req.params.id}`) |     res.redirect(302, `https://youtube.com/playlist?list=${req.params.id}`) | ||||||
| }) | }) | ||||||
|  |  | ||||||
|  | //Automagic ebay item redirects on /e/ | ||||||
|  | fastify.get('/e/:id', async (req, res) => { | ||||||
|  |     res.redirect(302, `https://ebay.de/itm/${req.params.id}`) | ||||||
|  | }) | ||||||
|  |  | ||||||
| //Normal shorturls | //Normal shorturls | ||||||
| fastify.get('/:shortcode', async (req, res) => { | fastify.get('/:shortcode', async (req, res) => { | ||||||
|     const shortcode = req.params.shortcode; |     const shortcode = req.params.shortcode; | ||||||
| @@ -221,7 +227,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 +243,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; | ||||||
|  |     }); | ||||||
|  |  | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -266,7 +289,7 @@ function checkKnownProviders(target) { | |||||||
|             target |             target | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     const amazonID = target.match(/https?:\/\/(www|smile|)\.?(amazon|smile)\.(de)(?:(?:\/.*\/|\/)(?:dp|gp))(\/product\/|\/)([A-Z0-9]+)/); |     const amazonID = target.match(/(?:https?:\/\/|)(www|smile|)\.?(amazon|smile)\.(de)(?:(?:\/.*\/|\/)(?:dp|gp))(\/product\/|\/)([A-Z0-9]+)/); | ||||||
|     if (amazonID) { |     if (amazonID) { | ||||||
|         const shortcode = `a/${amazonID[5]}` |         const shortcode = `a/${amazonID[5]}` | ||||||
|         return { |         return { | ||||||
| @@ -275,6 +298,15 @@ function checkKnownProviders(target) { | |||||||
|             target |             target | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |     const ebayID = target.match(/(?:[ebay]*(?:[\/]|[itm=])|^)([0-9]{9,12})/); | ||||||
|  |     if (ebayID) { | ||||||
|  |         const shortcode = `e/${ebayID[1]}` | ||||||
|  |         return { | ||||||
|  |             url: `${config.getBaseUrl()}/${shortcode}`, | ||||||
|  |             shortcode, | ||||||
|  |             target | ||||||
|  |         } | ||||||
|  |     } | ||||||
|     return null; |     return null; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -298,13 +330,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) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user