Giter Club home page Giter Club logo

boilerplate-ws's Introduction

Boilerplate Websocket Server

Build Status Coverage Status

Boilerplate para desenvolvimento de uma aplicação.

Instalação

Utilize @tadashi/boilerplate-create para iniciar o projeto.

npm i -g @tadashi/boilerplate-create
boilerplate-create

ou

npx --yes @tadashi/boilerplate-create

E siga as instruções do prompt.

Como utilizar

Após finalizado o scaffolding do projeto, instale os pacotes.

bin/node/pkg.js
bin/node/zera

Feito isso, o projeto está pronto para funcionar.

Para rodar local, utilize:

bin/local/start

E via docker, utilize:

bin/docker/start

Important

No docker, caso seja instalado um novo pacote, é necessário fazer o build da imagem novamente.

Pare o container (bin/docker/stop ou control + c) e rode novamente passando o parâmetro -b:

bin/docker/start -b

watch

O watch reinicia a aplicação caso ocorra alguma alteração.
Rodando via docker isso ocorre por padrão, mas local é necessário fazer algumas instalações e configurações.

bin/local/start -w

teste

Para executar os testes.

local:

bin/local/test

docker:

bin/docker/test

Imagem

Crie os arquivos de usuário e senha do registry que serão utilizados para fazer o push da imagem.

echo 'username' > .registry-user
echo 'password' > .registry-passwd

Verifique as suas variáveis de ambiente .env-*.
E para fazer o push da imagem de sua aplicação, execute:

bin/docker/image -e production

Deploy

Para executar o deploy é necessário alguns binários instalados:

  • envsubst by Bruno Haible
  • rsync by Andrew Tridgell, Wayne Davison and others

O fluxo do sistema de deploy é simples:

  1. Carrega as variáveis de ambiente (staging ou production)
  2. Executa o script bin/docker/image (se passado o parâmetro -i esse processo é ignorado)
  3. Cria o arquivo docker-compose-{VERSION}.yml utilizando o envsubst
  4. Envia os arquivos para o servidor via rsync
  5. Executa o docker stack deploy no servidor
bin/docker/deploy -e production

Exemplo

Utilize o wscat.

npm i -g wscat

Abra um shell e execute:

wscat -c 'ws://[::1]:5001/?access_token=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMiwiaWQiOiI2MjcxYmFiNWY2N2U5Y2NkNDkwMzNhYmIifQ.hmoUE_vayFKMKGz0v9iPLfIuneklDkL_qnD2n5QVKrYXmUwUqoJlSKGgafXIQGlyFxNZTucE8z8qdSRHZ-IXRQ'
Connected (press CTRL+C to quit)
> {"action": "direct", "message": "Olá", "to": "6271bab5f67e9ccd49033abc"}
> {"action": "me", "message": "Espelho, espelho meu!!"}
> {"action": "broadcast", "message": "Olá pessoal!"}

Em outro shell:

wscat -c 'ws://[::1]:5001/?access_token=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkFsYmVydG8gUm9iZXJ0byIsImFkbWluIjp0cnVlLCJpYXQiOjE1MTYyMzkwMjIsImlkIjoiNjI3MWJhYjVmNjdlOWNjZDQ5MDMzYWJjIn0.CEoDPZn3IRrP4Cob6V_C41FxiqZoNkI6maN6c9tvfMrzw8gB5WWxBSiGdUWJ9HF4drPJANgEvfHKL8C0gNeuxA'
Connected (press CTRL+C to quit)
< {"action": "direct", "message": "Bãooo?", "to": "6271bab5f67e9ccd49033abb"}
> {"action": "broadcast", "message": "ihhhhulll!!!"}

Buy me a coffee

BTC: bc1q7famhuj5f25n6qvlm3sssnymk2qpxrfwpyq7g4

License

MIT © Thiago Lagden

boilerplate-ws's People

Contributors

lagden avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

xtreamtrader

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.