Giter Club home page Giter Club logo

restify-orm-scaffold's Introduction

restify-orm-scaffold

License Coverage Status David dependency status for latest release TypeScript build

Simple baseline scaffold to get you started using TypeORM and/or Sequelize and/or Waterline on restify with TypeScript.

Install prerequisites

Node

  1. node & npm (tested with node v10.16.0 & npm v6.10.1)
  2. Run: npm install -g typings typescript bunyan
  3. cd to directory you've cloned this repo into
  4. Run: typings install
  5. Run: npm install

External

  • Database, e.g.: Postgres. Set RDBMS_URI env var accordingly, e.g.: postgres://username:password@hostname:port/database_name. Modify config.ts to use a different database.
  • Redis. Set REDIS_URL env var accordingly; otherwise defaults are used.
  • Set: DEFAULT_ADMIN_EMAIL and DEFAULT_ADMIN_PASSWORD env vars

Docker

Alternatively there is a Dockerfile and docker-compose.yml, so rather than installing dependencies (other than Docker), you can run:

Docker Compose

docker-compose up

Kubernetes

If you'd rather use Kubernetes to Docker Compose, then:

Docker

If you don't want to use Docker Compose, then assuming you have Redis and Postgresql running independently of Docker, or exposed in Docker through ports, you can then run:

docker run -e RDBMS_URI="$RDBMS_URI" \
           -e REDIS_HOST="$REDIS_HOST" \
           -e DEFAULT_ADMIN_EMAIL=foo \
           -e DEFAULT_ADMIN_PASSWORD=bar \
           -p 3000:3000 \
           --name "${PWD##*/}" \
           "${PWD##*/}_api"  # Name of the Docker image, the `_api` is suffixed by Docker Compose

Where RDBMS_URI and REDIS_HOST environment variables are set correctly for your system, in the form:

export RDBMS_URI='postgres://username:password@hostname:port/database_name'
export REDIS_HOST='host'

Configure a reverse proxy for server & static website files

Use a long nginxctl CLI command to create an nginx config and server it:

python -m nginxctl serve --temp_dir '/tmp' -b 'server' --server_name 'localhost' --listen '8080' -b 'location' '/api' --proxy_pass 'http://localhost:3000' --proxy_redirect 'off' -} -b 'location' '/' --root '/tmp/wwwroot' --try_files '$uri$args $uri$args/ /index.html' -} -}

Or just write a config (below is what the command generates… with 2 newlines thrown in):

server {
    server_name localhost;
    listen 8080;

    location /api {
        proxy_pass http://localhost:3000;
        proxy_redirect off;
    }

    location / {
        root /tmp/wwwroot;
        try_files $uri$args $uri$args/ /index.html;
    }
}

Compile+run app

tsc
node main.js

Misc

Cleanup compiled output

When *.js isn't present in .gitignore, clean out compiled js with this GNU findutils & Bash solution:

find -name '*.js.map' -type f -exec bash -c 'rm "${1}" "${1%????}"' bash {} \;

To delete all *.js outside of node_modules, use:

find \( -name node_modules -prune \) -o -name '*.js' -type f -exec rm {} \;

More complicated solution handling "foo.ts" & "foo.js" without "foo.js.map" coming at some point.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

restify-orm-scaffold's People

Contributors

samuelmarks avatar

Watchers

 avatar  avatar

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.