https://github.com/samuelmarks/restify-orm-scaffold
REST API scaffold with auth and user admin; built on Node.JS in TypeScript with restify and any ORM (waterline, TypeORM, sequelize).
https://github.com/samuelmarks/restify-orm-scaffold
Last synced: 9 months ago
JSON representation
REST API scaffold with auth and user admin; built on Node.JS in TypeScript with restify and any ORM (waterline, TypeORM, sequelize).
- Host: GitHub
- URL: https://github.com/samuelmarks/restify-orm-scaffold
- Owner: SamuelMarks
- License: apache-2.0
- Created: 2015-11-04T13:36:31.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-10-17T03:41:32.000Z (over 1 year ago)
- Last Synced: 2024-10-19T06:00:08.545Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 1.94 MB
- Stars: 6
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
restify-orm-scaffold
====================
[](https://opensource.org/licenses/Apache-2.0)
[](https://coveralls.io/github/SamuelMarks/restify-orm-scaffold)

Simple baseline scaffold to get you started using [TypeORM](https://github.com/typeorm/typeorm) and/or [Sequelize](https://github.com/sequelize/sequelize) and/or [Waterline](https://github.com/balderdashy/waterline) on [restify](https://github.com/restify/node-restify) with [TypeScript](https://github.com/Microsoft/TypeScript).
## Install prerequisites
### Node
0. node & npm (tested with node v10.16.0 & npm v6.10.1)
1. Run: `npm install -g typings typescript bunyan`
2. `cd` to directory you've cloned this repo into
3. Run: `typings install`
4. 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](https://github.com/SamuelMarks/restify-orm-scaffold/blob/master/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](https://docs.docker.com/install/#supported-platforms)), 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](https://github.com/offscale/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
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or )
- MIT license ([LICENSE-MIT](LICENSE-MIT) or )
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.