Giter Site home page Giter Site logo

shorturl-egg's Introduction

shorturl

shorturl powered by egg.js

QuickStart

see egg docs for more detail.

Development

$ npm install
$ npm run dev
$ open http://localhost:7001

Deploy

Use EGG_SERVER_ENV=prod to enable prod mode

$ EGG_SERVER_ENV=prod npm start

npm scripts

  • Use npm run lint to check code style.
  • Use npm test to run unit test.
  • Use npm run autod to auto detect dependencies upgrade, see autod for more detail.

docker-compose

cd docs/docker-compose
docker-compose up

see docs/docker-compose for more detail.

Config

Database

// mysql
DROP TABLE IF EXISTS  `url`;
CREATE TABLE `url` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `url` varchar(512) NOT NULL,
  `created` datetime DEFAULT CURRENT_TIMESTAMP,
  `hash` varchar(512) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=200 DEFAULT CHARSET=utf8mb4;
// elasticsearch

// geoip configure
PUT _ingest/pipeline/geoip
{
  "description" : "Add geoip info",
  "processors" : [
    {
      "geoip" : {
        "field" : "ip"
      }
    }
  ]
}

// mappings
PUT shorturl
{
  "mappings": {
    "view": {
      "_all": {
        "enabled": false
      },
      "properties": {
        "ip": {
          "type": "ip"
        },
        "date": {
          "type": "date"
        }
      }
    }
  }
}

Application

  • app/config/config.prod.js
'use strict';

exports.site = {
  domain: 'https://swz.li/',
};

exports.mysql = {
  client: {
    host: 'mysql',
    port: '3306',
    user: 'root',
    password: 'mysql',
    database: 'shorturl',
  },
};

exports.redis = {
  client: {
    port: 6379,
    host: 'redis',
    password: null,
    db: 0,
  },
};

exports.elasticsearch = {
  host: 'elasticsearch:9200',
};

Api

  • POST /api/v1/shorten
// request body
{
	"url":"http://www.baidu.com"
}

// response
{
  "url": "http://www.baidu.com",
  "hash": "QioWY",
  "shorturl": "http://localhost:7001/QioWY"
}
  • GET /api/v1/expand/:hash
{
  "id": 2,
  "url": "http://www.baidu.com",
  "created": "2017-07-24T03:42:06.000Z"
}
  • GET /api/v1/count
[
  {
    "id": 2,
    "url": "http://www.baidu.com",
    "created": "2017-07-24T03:42:06.000Z"
  },
  {
    "id": 1,
    "url": "http://www.baidu.com/?test=3",
    "created": "2017-07-23T06:56:48.000Z"
  }
]

shorturl-egg's People

Contributors

thonatos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

shorturl-egg's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.