hapi-starter-kit 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
hapi-starter-kit 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
hapi-starter-kit 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 MIT License
开发语言 JavaScript
操作系统 跨平台
软件类型 开源软件
所属分类 Web应用开发Web框架
开源组织
地区 不详
投 递 者 首席测试
适用人群 未知
收录时间 2021-11-30

软件简介

Hapi Starter Kit | Hapi based REST application boilerplate, uses async/await

Build Status Code Climate Test Coverage bitHound Overall Score bitHound Dependencies MIT License PRs Welcome

Overview

A lean boilerplate application for building RESTful APIs (Microservice) in Node.js using hapi.js. Follows industry standard best practices, and uses latest async/await ES8 feature. Bring your own front-end. Plug-in your own Database.

Features

Feature Summary
Uses latest ES8/ES2017 features (async/await) Uses latest ES7 and ES8 features including async/await
Application Configuration via config Node-config organizes hierarchical configurations for your app deployments. It lets you define a set of default parameters, and extend them for different deployment environments (development, qa, staging, production, etc.).
Auto Documentation via hapi-swagger This will self document the API interface. You can also tests your APIs using the Swagger interface.
Unit and Integration Tests via Mocha with async/await Demo unit and integration tests using latest ES7/ES8 features.
Code Coverage via istanbul Supports code coverage of ES8 code using istanbul and mocha. Code coverage reports are saved in coverage/ directory post yarn test execution. Open coverage/lcov-report/index.html to view coverage report. yarn test also displays code coverage summary on console. Code coverage can also be enforced overall and per file as well, configured via .istanbul.yml
Logging via bunyan Bunyan is simple and fast JSON logging library. Logs timestamp, machine name and process ID and most importantly makes it really easy to parse logs as it logs in JSON format. You can selectively turn on/off logs by setting log level via LOG_LEVEL env variable.
Code Linting via Standard JavaScript code linting is done using ESLint - a pluggable linter tool for identifying and reporting on patterns in JavaScript.
API parameter validation via joi Validate body, params, query, headers and cookies of a request (via middleware) and return a response with errors; if any of the configured validation rules fail. You won't anymore need to make your route handler dirty with such validations.
Application monitoring via New Relic Set NEW_RELIC_APP_NAME and NEW_RELIC_LICENSE_KEY environment variables in production environment to get metrics in New Relic Dashboard
Pre-commit hooks via husky Runs lint and tests before any commit is made locally, making sure that only tested and quality code goes through
Uses Sinon for spies, stubs and mocks Standalone and test framework agnostic JavaScript test spies, stubs and mocks
Uses nock for mocking http requests in integration tests Nock is an HTTP mocking and expectations library. It can be used to test modules that perform HTTP requests in isolation.
Uses yarn over npm Uses new released yarn package manager by facebook. You can read more about it here
Docker compatible Docker and Docker Compose files to develop and deploy via Docker
Uses EditorConfig EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs

Requirements

  • node.js >= 8.4.0
  • yarn >= 0.27.5
  • docker
    • Docker is optional and is required only if you want to develop and deploy using Docker

Getting Started

# Install dependencies
$ yarn

yarn

# Start Server
# Set environment variables defined in `config/custom-environment-variables.json` like `OPEN_WEATHER_API_KEY=xxx`
$ yarn start

yarn start

# Try GET /ping to make sure server is up
$ curl http://localhost:3030/ping
# Run Tests
$ yarn test

yarn test

Docker

Development

# copy sample.dev.env to dev.env
$ cp bin/sample.dev.env bin/dev.env
# Start Server
$ bash bin/development.sh

Docker Development

Tests

# copy sample.test.env to test.env
$ cp bin/sample.test.env bin/test.env
# Run Tests
$ bash bin/test.sh

docker test

Environment Configuration

config is used to configure application.

  • Default values of environment variables, which are common across all environments can be configured via config/default.json
  • Values specific to a particular environment can be set by creating a file with same name in config directory. Like config/test/json for test environment.
  • config/custom-environment-variables is used to read values from environment variables. For ex. if APP_PORT env var is set it can be accessed as config.get('app.port'). You can read more on custom environment variables here.

More Tasks

# Run lint
yarn lint

yarn lint

Deployment

  • Simply set environment variables defined in bin/sample.dev.env in your own environment (AWS, Heroku etc) and yarn start

Docker

  • Build the docker image
    • docker build -t hapi-starter-kit-oss .
  • Start Docker Container
    • docker run -d -p 3030:3030 --name hapi-starter-kit-oss hapi-starter-kit-oss

Documentation

  • hapi-swagger self documents all the APIs.
  • Visit http://localhost:3030/documentation to access the documentation after starting the server. Documentation

Miscellaneous

  • To turn off logs getting logged via good-console in development environment, remove it from plugins.js

Issues

Please feel free to open an issue if you can have any questions or trouble using this starter kit.

Contributions

Contributions are all welcome and encouraged. For code contributions submit a pull request with unit test.

License

This project is licensed under the MIT License

展开阅读全文

代码

评论 (0)

加载中
更多评论
暂无内容
发表了博客
2019/03/15 18:20

node -- hapi 学习

node learning 学习node,是为了后续项目可以正常开展,现在写个项目,若不是连接后台,请求数据,一切都不叫着项目了。正好借助掘金的小册,来推进学习 学习资料 YouTube 1 掘金 hapi.js 以下皆是按照掘金小册加上自己扩展一步步走过来的 hapi 学习 使用 hapi 时,对应的一些插件,由于插件很多,目前暂时写着用到的一些吧 hapi-swagger 用来生成 接口文档, 地址 服务地址/documentation env2 读取 .env 文件,可以用来配置文件...

0
0
发表了博客
2018/04/19 12:20

部署上次的Hapi到Windows+Docker,WindowsDocker

前言: 理论的就不多说了,具体的架构看图。web这里是上篇文章开发的Hapi服务,数据库Mysql,废话不多说,粗略的画了下,架构图如下: Mysql镜像拉取,配置 数据库镜像查找 docker search mysql   不多解释,这里我直接拉取Mysql镜像,并且把端口映射到宿主机8087,数据库默认密码设置123456 -d mysql 为刚刚上面查询到的镜像NAME,此时镜像和容器都已经创建 docker run --name test-mysql -p 8087:3306 -e MYSQL_ROOT_PASSW...

0
0
2018/07/09 15:51

KIT

#### 扩展名批量修改 import java.io.*; /** * JAVA实现的批量更改文件后缀名的程序。 * */ public class ExtBatchRename { /** * 修改程序。 * 内部递归调用,进行子目录的更名 * * [@param](https://my.oschina.net/u/2303379) path * 路径 * [@param](https://my.oschina.net/u/2303379) from * 原始的后缀名,包括那个(.点) * [@param](https://my.oschina.net/u/2303379) to * 改名的后缀,也包括那个(.点) */ public voi...

0
0
发表于软件架构专区
2015/06/17 16:27

NodeJs框架对比:Express、Koa、Hapi

https://www.airpair.com/node.js/posts/nodejs-framework-comparison-express-koa-hapi 1 Introduction Express.js is the most popular Node.js web application framework used today. It seems to be the base dependency in most Node.js web applications, even some popular frameworks like Sails.js are built off of Express. However there are more options available that have the same "sinatra-like" feel to t...

0
2
2016/07/21 11:38

Lua Starter

![mahua](http://www.lua.org/images/lua.gif) 标签: Lua #Lua starter Lua 是一种轻量小巧的脚本语言,用标准C语言编写并以源代码形式开放, 其设计目的是为了嵌入应用程序中,从而为应用程序提供灵活的扩展和定制功能。 Lua 是巴西里约热内卢天主教大学(Pontifical Catholic University of Rio de Janeiro)里的一个研究小组,由Roberto Ierusalimschy、Waldemar Celes 和 Luiz Henrique de Figueiredo所组成并于1993年开发...

0
11
发表于开发技能专区
2020/09/29 11:07

go-kit 入门(翻译)

# 第一原则 让我们创建一个最小的 Go-kit 服务。现在,我们将使用单独的 `main.go` 文件。 # 你的商业逻辑 您的服务从您的业务逻辑开始。 在Go kit中,我们将服务建模为**接口**. ```go // StringService provides operations on strings. import "context" type StringService interface { Uppercase(string) (string, error) Count(string) int } ``` 该接口将有一个实现。 ```go import ( "context" "errors" "strings" ) ty...

0
0
没有更多内容
加载失败,请刷新页面
点击加载更多
加载中
下一页
暂无内容
0 评论
0 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部