Giter Site home page Giter Site logo

hotel-nodejs's Introduction

test

Hotel Management System

This project was created using restify and is basically an API secured with JWT, sequelizejs was selected as ORM and joi for user schema definitions to make data validations.

Server Configuration

First of all, don't forget to configure your database (look into the resource folder the schema), the sql file was generated to use MySQL or MariaDB.

Installing Dependencies

$ npm install

Setting up

Inside src/config there's configuration environment variables, setup your database here.

Running

To start the project, just run on your console

$ npm start

In case you need to debug, you can use chrome debugger through inspect plugin (don't forget to enabled using chrome://inspect once that you have ran the server)

$ npm run inspect

Logging

By default node-bunyan is used for logging to a file (./logs/{{NODE_ENV}}-{{SERVER:NAME}}.log).

Environments

NODE_ENV is not yet used to allow different configurations for development / production. The only thing it does is disabling the Auth- and CORS-Plugin in development.

$ NODE_ENV=production node app.js

Generate cert key files

Execute the next command

openssl genrsa -out server.key 2048
openssl rsa -in server.key -out server.pem -outform PEM -pubout

Once you have the keys, move the generated files into keys/ folder or whatever you want, just don't forget to configure the right path into src/config/{development | production}.config.json

Known issues

There's an issue with bunyan, to fix this you will need to read this link: trentm/node-bunyan#525 (comment)

and if your configuration file is ok, just execute npm start to run the project

General Instructions

Inside src/controllers you will find all different routes enabled organized by folder, the most important at the begining is home which is used to register users and login them.

Once the server is running locally the api is ready to be consumed at the port 1337

Registering users

POST http://[::]:1337/register
Content-Type: application/json
{
	"username": "jackfiallos",
	"password": "123456",
	"name": "Jack",
	"lastname": "Fiallos",
	"type": "admin"
}

By default new users are created with the active flag 0/false, meaning the user is inactive (you can change this directly in your local DB in order to let the user login).

Also, exist 2 different types of users, "admin" and "user" (this was created intentionally thinking in mind roles / a future feature)

Login users

POST http://[::]:1337/
Content-Type: application/json
{
	"username": "jackfiallos",
	"password": "123456"
}

If the credentials given are ok, the server will return a valid token that needs to be used to make any other request.

Making requests

All api endpoints are secure and you will need the token to call them, so once you get a token after login, in every request you need to send the token using the "Authorization" header with the value "BEARER {token}".

hotel-nodejs's People

Contributors

minhnguyenle avatar

Watchers

 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.