Skip to content

Commit

Permalink
[v2-beta] Move from Neo4j to Postgres, use TypeScript for server. Fixes
Browse files Browse the repository at this point in the history
#217, #197, #190, #75  (#220)

* Disable underscore-dangle rule

* Add mongoose package

* Use mongodb for auth queries

* Move to MongoDB and TypeScript

* Init plan

* Update steps

* Update config

* 💥 Move to Postgres from MongoDB

* Remove unused

* Improve migration scripts

* Decrease concurrent connections

* Add skip and fix query

* Add migration guide

* Increase cahr limit to 1023

* Decrease target limit to 1023

* Update migration guid with important note

* Update example with new env vars

* Update with v2 guides

* Fix migrating visit referrers

* Add script to delete duplicated visit relationship

* Add shortUrl to link response for backward compatibility

* Linting

* Fix creating anonymous links

* Fix IP cooldown not working

* Fix deleting links by deleting visits of links first

* Fix and improve links migration script

* Add fail note to migration

* 2.0.0

* Fix main path

* Fix limit when getting list of links

* Improve table nav buttons clicking and listing

* Return countAll as number instead of string

* Fix proptype warning

* Fix not authenticating user on initial load. Fixes #71
  • Loading branch information
poeti8 committed Oct 8, 2019
1 parent 1249bc9 commit 33320f0
Show file tree
Hide file tree
Showing 78 changed files with 5,087 additions and 2,213 deletions.
2 changes: 1 addition & 1 deletion .babelrc
@@ -1,4 +1,4 @@
{
"presets": ["next/babel"],
"presets": ["next/babel", "@zeit/next-typescript/babel"],
"plugins": [["styled-components", { "ssr": true, "displayName": true, "preprocess": false }]]
}
3 changes: 2 additions & 1 deletion .eslintignore
@@ -1,4 +1,5 @@
.next/
flow-typed/
node_modules/
client/**/__test__/
client/**/__test__/
production-server
62 changes: 35 additions & 27 deletions .eslintrc
@@ -1,35 +1,43 @@
{
"extends": [
"airbnb",
"prettier",
"prettier/react"
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"parser": "babel-eslint",
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.server.json",
},
"plugins": ["@typescript-eslint"],
"rules": {
"eqeqeq": ["warn", "always", { "null": "ignore" }],
"no-useless-return": "warn",
"no-var": "warn",
"no-console": "warn",
"max-len": ["warn", { "comments": 80 }],
"no-param-reassign": ["warn", { "props": false }],
"require-atomic-updates": 0,
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/no-unused-vars": "off", // "warn" for production
"@typescript-eslint/no-explicit-any": "off", // "warn" for production
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/no-object-literal-type-assertion": "off",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/explicit-function-return-type": "off"
},
"env": {
"es6": true,
"browser": true,
"node": true
"node": true,
"mocha": true
},
"rules": {
"react/jsx-filename-extension": [
1,
{
"extensions": [
".js",
".jsx"
]
}
],
"prettier/prettier": [
"error",
{
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 100
}
],
"consistent-return": "off"
"globals": {
"assert": true
},
"settings": {
"react": {
"version": "detect"
}
},
"plugins": [
"prettier"
]
}
17 changes: 14 additions & 3 deletions .example.env
Expand Up @@ -4,11 +4,18 @@ PORT=3000
# The domain that this website is on
DEFAULT_DOMAIN="localhost:3000"

# Neo4j database credential details
DB_URI="bolt://localhost"
DB_USERNAME=
# Postgres database credential details
DB_HOST=localhost
DB_NAME=postgres
DB_USER=
DB_PASSWORD=

# ONLY NEEDED FOR MIGRATION !!1!
# Neo4j database credential details
NEO4J_DB_URI="bolt://localhost"
NEO4J_DB_USERNAME=neo4j
NEO4J_DB_PASSWORD=BjEphmupAf1D5pDD

# Redis host and port
REDIS_DISABLED=false
REDIS_HOST="127.0.0.1"
Expand All @@ -25,6 +32,9 @@ NON_USER_COOLDOWN=0
# Max number of visits for each link to have detailed stats
DEFAULT_MAX_STATS_PER_LINK=5000

# Use HTTPS for links with custom domain
CUSTOM_DOMAIN_USE_HTTPS=false

# A passphrase to encrypt JWT. Use a long and secure key.
JWT_SECRET=securekey

Expand All @@ -44,6 +54,7 @@ GOOGLE_SAFE_BROWSING_KEY=
# Google Analytics tracking ID for universal analytics.
# Example: UA-XXXX-XX
GOOGLE_ANALYTICS=
GOOGLE_ANALYTICS_UNIVERSAL=

# Google Analytics tracking ID for universal analytics
# This one is used for links
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -5,4 +5,5 @@ node_modules/
client/config.js
client/old.config.js
server/config.js
server/old.config.js
server/old.config.js
production-server
44 changes: 44 additions & 0 deletions MIGRATION.md
@@ -0,0 +1,44 @@
# Migrate database from Neo4j to Postgres

As explained in issue #197, Kutt is ditching Neo4j in favor of Postgres in version 2. But what happens to old data? Well, I have created migration scripts that you can use to transfer data from your Neo4j database to your new Postgres database.

### 🚧 IMPORTANT: v2 is still in beta, proceed carefully!!1!

## General recommendations

- Importing Neo4j data into local Neo4j database and migrate from there would speed things up.
- Use local Postgres database (where app lives), because using a remote database server will be way slower. If you're doing this locally, you can import data from local database to the remote one after migration has finished. I used this command to move data:

## 1. Set up a Postgres database

Set up a Postgres database, either on your own server or using a SaaS service.

## 2. Pull and run Kutt's new version

Right now version 2 is in beta. Therefore, pull from `v2-beta` branch and create and fill the `.env` file based on `.example.env`.

**NOTE**: Run the app at least once and let it create and initialize tables in the database. You just need to do `npm run dev` and wait for it to create tables. Then check your database to make sure tables have been created. (If your production database is separate, you need to initialize it too).

## 3. Migrate data using scripts

First, do `npm run build` to build the files. Now if you check `production-server/migration` folder you will fine 4 files. You can now run these scripts one by one.

**NOTE:** that the order of running the scripts is important.

**NOTE:** Step 4 is going to take a good chunk of time.

**NOTE:** If step 4 fails at any stage, you should delete links and visits data from the database and try again.

```
// 1. Migrate data: Hosts
node production-server/migration/01_hosts.js
// 2. Migrate data: Users
node production-server/migration/02_users.js
// 3. Migrate data: Domains
node production-server/migration/03_domains.js
// 4. Migrate data: Links
node production-server/migration/04_links.js
```
107 changes: 65 additions & 42 deletions README.md
Expand Up @@ -4,65 +4,77 @@

**Kutt** is a modern URL shortener with support for custom domains. Shorten URLs, manage your links and view the click rate statistics.

*Contributions and bug reports are welcome.*
_Contributions and bug reports are welcome._

[https://kutt.it](https://kutt.it)

[![Build Status](https://travis-ci.org/thedevs-network/kutt.svg?branch=develop)](https://travis-ci.org/thedevs-network/kutt)
[![Build Status](https://travis-ci.org/thedevs-network/kutt.svg?branch=v2-beta)](https://travis-ci.org/thedevs-network/kutt)
[![Contributions](https://img.shields.io/badge/contributions-welcome-brightgreen.svg)](https://github.com/thedevs-network/kutt/#contributing)
[![GitHub license](https://img.shields.io/github/license/thedevs-network/kutt.svg)](https://github.com/thedevs-network/kutt/blob/develop/LICENSE)
[![Twitter](https://img.shields.io/twitter/url/https/github.com/thedevs-network/kutt/.svg?style=social)](https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2Fthedevs-network%2Fkutt%2F)

## Kutt v2 (🚧 beta)

The new version of Kutt is here. In version 2, we used TypeScript and we moved from Neo4j to PostgreSQL database in favor of performance and we're working on adding new features.

If you're coming from v1, refer to [MIGRATION.md](MIGRATION.md) to migrate data from Neo4j to PostgreSQL.

You can still find the stable version (v1) in the [v1](https://github.com/thedevs-network/kutt/tree/v1) branch.

## Table of Contents
* [Key Features](#key-features)
* [Stack](#stack)
* [Setup](#setup)
* [Browser Extensions](#browser-extensions)
* [API](#api)
* [Integrations](#integrations)
* [3rd Party API Packages](#3rd-party-api-packages)
* [Contributing](#contributing)

- [Key Features](#key-features)
- [Stack](#stack)
- [Setup](#setup)
- [Browser Extensions](#browser-extensions)
- [API](#api)
- [Integrations](#integrations)
- [3rd Party API Packages](#3rd-party-api-packages)
- [Contributing](#contributing)

## Key Features
* Free and open source.
* Custom domain support.
* Custom URLs for shortened links
* Setting password for links.
* Private statistics for shortened URLs.
* View and manage your links.
* RESTful API.

- Free and open source.
- Custom domain support.
- Custom URLs for shortened links
- Setting password for links.
- Private statistics for shortened URLs.
- View and manage your links.
- RESTful API.

## Stack
* Node (Web server)
* Express (Web server framework)
* Passport (Authentication)
* React (UI library)
* Next (Universal/server-side rendered React)
* Redux (State management)
* styled-components (CSS styling solution library)
* Recharts (Chart library)
* Neo4j (Graph database)

- Node (Web server)
- Express (Web server framework)
- Passport (Authentication)
- React (UI library)
- Next (Universal/server-side rendered React)
- Redux (State management)
- styled-components (CSS styling solution library)
- Recharts (Chart library)
- PostgreSQL (database)

## Setup
You need to have [Node.js](https://nodejs.org/), [Neo4j](https://neo4j.com/) and [Redis](https://redis.io/) installed on your machine.

1. Clone this repository or [download zip](https://github.com/thedevs-network/kutt/archive/develop.zip).
2. Copy `.example.env` to `.env` and fill it properly.
You need to have [Node.js](https://nodejs.org/), [PostgreSQL](https://www.postgresql.org/) and [Redis](https://redis.io/) installed.

1. Clone this repository or [download zip](https://github.com/thedevs-network/kutt/archive/v2-beta.zip).
2. Copy `.example.env` to `.env` and fill it properly.
3. Install dependencies: `npm install`.
4. Start Neo4j database.
5. Run for development: `npm run dev`.
6. Run for production: `npm run build` then `npm start`.
4. Run for development: `npm run dev`.
5. Run for production: `npm run build` then `npm start`.

**[Visit our wiki for a more complete setup and development guide.](https://github.com/thedevs-network/kutt/wiki/Setup-and-deployment)**

**Docker:** You can use Docker to run the app. Read [docker-examples](/docker-examples) for more info.

## Browser Extensions

Download Kutt's extension for web browsers via below links. You can also find the source code on [kutt-extension](https://github.com/abhijithvijayan/kutt-extension).
* [Chrome](https://chrome.google.com/webstore/detail/kutt/pklakpjfiegjacoppcodencchehlfnpd)
* [Firefox](https://addons.mozilla.org/en-US/firefox/addon/kutt/)

- [Chrome](https://chrome.google.com/webstore/detail/kutt/pklakpjfiegjacoppcodencchehlfnpd)
- [Firefox](https://addons.mozilla.org/en-US/firefox/addon/kutt/)

## API

In addition to the website, you can use these APIs to create, delete and get URLs.

### Types
Expand All @@ -85,11 +97,13 @@ All API requests and responses are in JSON format.
Include the API key as `X-API-Key` in the header of all below requests. Available API endpoints with body parameters:

**Get shortened URLs list:**

```
GET /api/url/geturls
```

Returns:

```
{
list {Array<URL>} List of URL objects
Expand All @@ -98,32 +112,40 @@ Returns:
```

**Submit a link to be shortened**:

```
POST /api/url/submit
```

Body:
* `target`: Original long URL to be shortened.
* `customurl` (optional): Set a custom URL.
* `password` (optional): Set a password.
* `reuse` (optional): If a URL with the specified target exists returns it, otherwise will send a new shortened URL.

- `target`: Original long URL to be shortened.
- `customurl` (optional): Set a custom URL.
- `password` (optional): Set a password.
- `reuse` (optional): If a URL with the specified target exists returns it, otherwise will send a new shortened URL.

Returns: URL object

**Delete a shortened URL** and **Get stats for a shortened URL:**

```
POST /api/url/deleteurl
GET /api/url/stats
```

Body (or query for GET request)
* `id`: ID of the shortened URL.
* `domain` (optional): Required if a custom domain is used for short URL.

- `id`: ID of the shortened URL.
- `domain` (optional): Required if a custom domain is used for short URL.

## Integrations

### ShareX

You can use Kutt as your default URL shortener in [ShareX](https://getsharex.com/). If you host your custom instance of Kutt, refer to [ShareX wiki](https://github.com/thedevs-network/kutt/wiki/ShareX) on how to setup.

### Alfred Workflow

Download Kutt's official workflow for [Alfred](https://www.alfredapp.com/) app from [alfred-kutt](https://github.com/thedevs-network/alfred-kutt) repository.

## 3rd Party API packages
Expand All @@ -137,6 +159,7 @@ Download Kutt's official workflow for [Alfred](https://www.alfredapp.com/) app f
| Bash | [kutt-bash](https://git.fossdaily.xyz/caltlgin/kutt-bash) | Simple command line program for Kutt |

## Contributing

Pull requests are welcome. You'll probably find lots of improvements to be made.

Open issues for feedback, requesting features, reporting bugs or discussing ideas.
Expand Down

0 comments on commit 33320f0

Please sign in to comment.