Skip to content

REST API scaffold with auth and user admin; built on Node.JS in TypeScript with restify and any ORM (waterline, TypeORM, sequelize).

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

SamuelMarks/restify-orm-scaffold

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

restify-orm-scaffold

License Coverage Status 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 / Podman

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

0. Build image for this repo

docker build -t restify-orm-scaffold_api_1 .

1. 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.

About

REST API scaffold with auth and user admin; built on Node.JS in TypeScript with restify and any ORM (waterline, TypeORM, sequelize).

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published