项目作者: fhsinchy

项目描述 :
An experimental blogging application developed with Docker, Deno, Oak and MySQL
高级语言: TypeScript
项目地址: git://github.com/fhsinchy/deno-blog.git
创建时间: 2020-05-22T13:19:33Z
项目社区:https://github.com/fhsinchy/deno-blog

开源协议:MIT License

下载


Deno Blog

This is an experimental blogging API developed with Docker, Deno, Oak and MySQL.

:warning: WARNING
The code from this API should not be deemed as ideal as all the functionalities are implemented in a very naive way. The goal was to test things out with this new runtime, not to build a production quality API.

Development Task List

System Requirements

Libraries Used

Project Structure

  1. .
  2. ├── Dockerfile
  3. ├── app.ts
  4. ├── controllers
  5. ├── auth.ts
  6. └── blogs.ts
  7. ├── db
  8. └── mysql.ts
  9. ├── deps.ts
  10. ├── docker-compose.yml
  11. ├── docker-entrypoint-initdb.d
  12. ├── blogs.sql
  13. └── users.sql
  14. ├── helpers
  15. └── between.ts
  16. ├── middleware
  17. ├── authorize.ts
  18. ├── error.ts
  19. ├── logger.ts
  20. └── timer.ts
  21. ├── models
  22. ├── Blog.ts
  23. └── User.ts
  24. └── routes
  25. ├── auth.ts
  26. ├── blogs.ts
  27. └── home.ts

There are eight directories in the project -

  • api contains server.ts, responsible for initiating the application instance. It also registers four universal middleware.
  • controllers directory contains logic for all the api endpoints. Logic for a certain endpoint is encapsulated inside relevantly named files.
    • auth.ts contains logic regarding registration of users and generation of JWT tokens.
    • blogs.ts contains logic regarding CRUD operations of blog posts.
  • db directory contains necessary code for connecting to the database.
  • docker-entrypoint-initdb.d contains sql files for initializing the database.
  • helpers contains small helper functions for reusability.
  • middleware directory contains middleware functions for reusability.
    • authorize.ts handles validation of JWT tokens.
    • error.ts handles all errors centrally.
    • logger.ts logs all requests to the console.
    • timer.ts logs request times to the console.
  • models contains classes containing functions for querying the database.
  • routes contains necessary code for registering the controller functions as middleware route endpoints.

There are four orphan files in the project root:

  • Dockerfile for building the api container.
  • app.ts is responsible for registering all endpoints to the main app instance and firing up the server.
  • deps.ts imports and exports all the necessary dependencies.
  • docker-compose.yml file for building and running multi-container application.

Instructions

Clone this repository anywhere you want. Open up terminal and use following command to build and run the application -

  1. docker-compose up --build

There will be a wall of text but look for something like following -

  1. db_1 | 2020-06-08T17:27:05.115386Z 0 [Note] Event Scheduler: Loaded 0 events
  2. db_1 | 2020-06-08T17:27:05.116258Z 0 [Note] mysqld: ready for connections.
  3. db_1 | Version: '5.7.30' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)

The application should be running on http://127.0.0.1:3000 address. A postman collection containing all the routes can be found inside postman-collection directory.

You can stop the application by pressing control + c combination. If you want to stop and delete all built images issue following command -

  1. docker-compose down

Use following command if you don’t want the containers and images to be deleted -

  1. docker-compose stop

You can restart the application with following command -

  1. docker-compose up

You can learn more about docker-compose command line interface from Compose command-line reference

Postman Collection

The postman-collection/deno-blog.postman_collection.json file can be imported inside Postman for testing out the endpoints.