Giter VIP home page Giter VIP logo

hapi-typescript-example's Introduction

NodeJS-Hapi TypeScript Scaffolding

A NodeJS + HapiJS(17) with Typescript Starter kit to build standard projects.

Installation

  • npm run setup (install nuget packages & typings)

Important Note

  • If working with NodeJS 10.0.0, Kindly delete the package.lock.json file then try npm install

Run

  • gulp build (build ts files)
  • gulp test (run mocha tests)
  • gulp tslint (run tslint)
  • gulp watch (watch ts files)
  • npm run start (start the application)
  • npm run watch (restart the application when files change)

Features

  • Project Structure - Feature oriented
  • Hapijs - REST Api
  • Swagger - documentation
  • Jwt - authentication
  • Mongoose - MongoDb
  • nconf - configurations
  • Logging - MongoDB collection based logging
  • Unit Tests - chai + sinon + mocha

Running on port 5000 ex: localhost:5000/docs

Have fun :)

hapi-typescript-example's People

Contributors

alirazaalvi avatar lostdalek avatar talento90 avatar wilsongp avatar xdankit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hapi-typescript-example's Issues

Plugin load order & server startup

FYI, when upgrading hapi and deps I ended up with a race condition. hapi-auth-jwt2 wasn't registering the "jwt" auth mechanism before the server started up--as they are async--and the server failed to startup.

Error: Unknown authentication strategy jwt in /tasks/{id}

I've refactored the plugin / server startup code to be promise-ified for this case. Not sure if it's an issue without the updated lib versions, but from what I can tell it may be. Might be worth mentioning or pointing out in the docs in case someone else runs into it. But if nothing else it's here.

My changes can be found here: https://github.com/arimus/hapi-typescript-example

Cheers & thanks for the bootstrap.

how to add prefix to route

how to add router prefix

I added it in configuration/config.de.json and it does not work

example:
{
"database": {
"connectionString": "mongodb://localhost/taskdb-dev"
},
"server": {
"routes": {
"prefix": "/api"
},

"port": 5000,
"jwtSecret": "random-secret-password",
"jwtExpiration": "1h",
"plugins": [
"logger",
"swagger",
"jwt-auth"
]
}
}

Request is not received to server from hapi-swagger UI.

Great Sample, Following it for the future projects.
I cloned the repo and started the server. Everything runs fine except request from swagger UI does not work. GET request for getting all tasks executes. No POST request is received by server.

What's the problem? Same works fine with Pure Hapijs ES5.

how can I add a route to serve static files?

Hello, thank you for the great example!

I'm trying to add a route to serve static files using inert,
but I'm not able to use the "h" method like in the inert examples:

I tried adding a route like this:

server.route({
        method: 'GET',
        path: '/staticpath', //or public..
        config: {
            handler: function(request, h){
              //here i can't get the h, just the reply
               return h.file("public/index.html");
            },
            tags: ['api', 'virtual'],
            description: 'Virtual Get user info'
            }

        }
    });

I keep getting the error
Property 'file' does not exist on type 'ReplyWithContinue'.

I found this on type definition

  • NOTE: it's not possible to type the result of this action.
    • It's advised that in a custom definition file, you extend the ReplyNoContinue
    • and ReplyWithContinue functions. See Inert .file for an example.
    • Or if it is not part of a library / plugin then you use a namespace within
    • your code to type the request, server and or reply. See
    • [tests/server/decorate.ts]

But I don't know how to extend the ReplyWithContinue definitions
hope I explained my problem,
and sorry for my english !

logger add config

hi for good-console add this code and install package good-squeeze

file logger/index

const opts = {
                ops: {
                    interval: 1000
                },
                reporters: {
                    consoleReporter: [{
                        module: 'good-squeeze',
                        name: 'Squeeze',
                        args: [{ error: '*', log: '*', response: '*', request: '*' }]
                    }, {
                        module: 'good-console'
                    }, 'stdout']
                }
            };

How well can hapi apps leverage Typescript?

Hello. Thank you so much for doing this. I'm a long-time Java dev, and after creating my first Express server in vanilla JS, I vowed to never again do without static type checking.

I'm drawn to hapi for a number of reasons, but the more I read, the more worried I get that I wouldn't be able to leverage strong type checking.

How do you get static type checking in the following areas?

  • registered server methods
  • registered app settings
  • emitted plugin events
  • route pre-processing methods

It also seems to me that hapi goes out of its way to avoid the benefits of CommonJS, winging its own solutions that seem less optimal. There's no need for hapi's cross-plugin global namespaces. I don't see why module scoped variables have to go in internals, which is itself module-scoped.

I've only written demo hapi servers so far, am trying to decide whether to proceed. What can you tell me about the pros and cons of trying to get static type checking on top of hapi?

Thanks for any help you can provide!

Unable to create new routes properly

I tried to create routes but its not visible in swagger and even i'm not able to access it. but after sometime few of them created routes are accessible but even after removing that route code the routes are accessible don't know how.

Is this a caching issue or something else. Even i tried to create a new controller and directory but still the routes were not visible in swagger

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.