Giter Site home page Giter Site logo

randyscotsmithey / feathers-realworld-example-app Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gothinkster/realworld-starter-kit

29.0 2.0 6.0 246 KB

Feathers implementation for RealWorld example app

License: MIT License

HTML 10.89% JavaScript 89.11%

feathers-realworld-example-app's Introduction

RealWorld Example App

RealWorld Backend Build Status

Feathers codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.

Demo    RealWorld

This codebase was created to demonstrate a fully fledged fullstack application built with Feathers (and Mongoose) including CRUD operations, authentication, routing, pagination, and more.

We've gone to great lengths to adhere to the Feathers community styleguides & best practices.

For more information on how to this works with other frontends/backends, head over to the RealWorld repo.

How it works

Feathers is a service oriented REST and Real Time API layer. Endpoints are defined as services.

Application Structure

  • app.js - Entry point for the application.
  • config/ - Configuration/environment variables for the server.
  • src/services/ - Service implementations
  • src/middleware/ - Middleware implementations
  • src/models/ - Schema definitions for our Mongoose models(Easily changed to use other databases).
  • src/hooks/ - Hooks for running code before and after services. Used for formatting requests and responses correctly.
  • src/common/ - Common helper functions.

Getting started

To get the Feathers server running locally:

  • Clone this repo
  • cd feathers-realworld-example-app
  • npm install to install all required dependencies
  • Set environment variable MONGODB_FEATHERS_REALWORLD to the connection string for your mongodb instance (You can install a community edition instructions or create an instance on mLab: instructions).
  • npm start to start the local server (or npm test to run tests).

feathers-realworld-example-app's People

Contributors

alonski avatar anishkny avatar ericsimons avatar esakkiraj avatar optikfluffel avatar randyscotsmithey 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

Watchers

 avatar  avatar

feathers-realworld-example-app's Issues

"error: NotAuthenticated: invalid signature when running local with vue.js" frontend

I first managed to get a fully working vue-js Node.js Express setup as shown at: gothinkster/node-express-realworld-example-app#116 which indicates that the Vue setup and my MongoDB are actually working.

So now I wanted to replace the Node.js Express backend with this FeathersJS backend at 8bc3a09 and I ran it with:

MONGODB_FEATHERS_REALWORLD=mongodb://localhost:27017/feathers_realworld npm start

and patched the Vue frontend to point it to this server:

diff --git a/src/common/config.js b/src/common/config.js
index 03af84e..592a4fb 100644
--- a/src/common/config.js
+++ b/src/common/config.js
@@ -1,2 +1,2 @@
-export const API_URL = "https://conduit.productionready.io/api";
+export const API_URL = "http://localhost:3030/api";
 export default API_URL;

but then, when I visit the homepage at http://localhost:8080/ , the "Loading articles..." never disappears, indicating a problem, and on the server I see:

> [email protected] start /home/ciro/git/feathers-realworld-example-app
> node src/

info: mongodb://localhost:27017/feathers_realworld
(node:222399) Warning: Accessing non-existent property 'count' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:222399) Warning: Accessing non-existent property 'findOne' of module exports inside circular dependency
(node:222399) Warning: Accessing non-existent property 'remove' of module exports inside circular dependency
(node:222399) Warning: Accessing non-existent property 'updateOne' of module exports inside circular dependency
info: Feathers application started on http://localhost:3030
error: NotAuthenticated: invalid signature
    at new NotAuthenticated (/home/ciro/git/feathers-realworld-example-app/node_modules/@feathersjs/errors/lib/index.js:93:17)
    at /home/ciro/git/feathers-realworld-example-app/node_modules/@feathersjs/authentication/lib/hooks/authenticate.js:87:31
error: NotAuthenticated: invalid signature
    at new NotAuthenticated (/home/ciro/git/feathers-realworld-example-app/node_modules/@feathersjs/errors/lib/index.js:93:17)
    at /home/ciro/git/feathers-realworld-example-app/node_modules/@feathersjs/authentication/lib/hooks/authenticate.js:87:31

Any clues?

10 tests failing out 65

On 8bc3a09 after the interactive browser usage seems OK, I tried:

MONGODB_FEATHERS_REALWORLD=mongodb://localhost:27017/mydb npm run test

and the failures were:

  55 passing (15s)
  10 failing

  1) 'articles' service - client
       Run tests using client and server
         creates a user, encrypts password, logs in:
     Conflict: username: value already exists.
      at new Conflict (node_modules/@feathersjs/errors/lib/index.js:142:17)
      at convert (node_modules/@feathersjs/errors/lib/index.js:239:7)
      at toError (node_modules/@feathersjs/rest-client/lib/base.js:12:9)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at async Context.<anonymous> (test/services/client-articles.test.js:54:14)

  2) 'tags' service
       Run tests using client and server
         creates a user, encrypts password, logs in:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/ciro/git/feathers-realworld-example-app/test/services/tags.test.js)
      at listOnTimeout (internal/timers.js:549:17)
      at processTimers (internal/timers.js:492:7)

  3) 'tags' service
       Run tests using client and server
         Creates an Article with tags:

      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert.ok(tags.tags.length === 2)

      + expected - actual

      -false
      +true

      at Context.<anonymous> (test/services/tags.test.js:67:14)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  4) 'tags' service
       Run tests using client and server
         Adds another article checks for the tag order:

      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert.ok(tags.tags.length === 3)

      + expected - actual

      -false
      +true

      at Context.<anonymous> (test/services/tags.test.js:79:14)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  5) 'tags' service
       Run tests using client and server
         Adds a third article checks for the tag order:

      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert.ok(tags.tags.length === 3)

      + expected - actual

      -false
      +true

      at Context.<anonymous> (test/services/tags.test.js:92:14)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  6) 'tags' service
       Run tests using client and server
         Adds a fourth article checks for the tag order:

      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert.ok(tags.tags.length === 3)

      + expected - actual

      -false
      +true

      at Context.<anonymous> (test/services/tags.test.js:105:14)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  7) 'tags' service
       Run tests using client and server
         cleans up first article and checks tags:

      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert.ok(tags.tags.length === 2)

      + expected - actual

      -false
      +true

      at Context.<anonymous> (test/services/tags.test.js:116:14)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  8) 'tags' service
       Run tests using client and server
         cleans up another article and checks tags:

      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert.ok(tags.tags.length === 2)

      + expected - actual

      -false
      +true

      at Context.<anonymous> (test/services/tags.test.js:127:14)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  9) 'tags' service
       Run tests using client and server
         cleans up third article and checks tags:

      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert.ok(tags.tags.length === 1)

      + expected - actual

      -false
      +true

      at Context.<anonymous> (test/services/tags.test.js:138:14)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  10) 'tags' service
       Run tests using client and server
         cleans up fourth article and checks tags and cleans up user:

      AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  assert.ok(tags.tags.length === 0)

      + expected - actual

      -false
      +true

      at Context.<anonymous> (test/services/tags.test.js:178:14)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

Ubuntu 20.10.

1)

If I narrow that error to a single test run with manually cleaned DB:

MONGODB_FEATHERS_REALWORLD=mongodb://localhost:27017/mydb mocha test/services/client-articles.test.js --exit -g 'creates a user, encrypts password, logs in'
info: mongodb://localhost:27017/mydb2

the first failure is always:

  'articles' service - client
Feathers application started on http://localhost:3000
    Run tests using client and server
      1) creates a user, encrypts password, logs in


  0 passing (2s)
  1 failing

  1) 'articles' service - client
       Run tests using client and server
         creates a user, encrypts password, logs in:
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/home/ciro/git/feathers-realworld-example-app/test/services/client-articles.test.js)
      at listOnTimeout (internal/timers.js:549:17)
      at processTimers (internal/timers.js:492:7)

If I force an increased timeout it passes on a clean DB:

MONGODB_FEATHERS_REALWORLD=mongodb://localhost:27017/mydb4 mocha test/services/client-articles.test.js --exit -g 'creates a user, encrypts password, logs in' --timeout 10000

If I re-run on the same non-clean DB, I get the user already exists. So we just have to clean up the database before running those tests.

There's some documentation for this at: https://docs.feathersjs.com/guides/basics/testing.html#test-database-setup Their approach seems to be to just clear up the database once before the run, and then create users with different names for each test, which is not ideal. Rails has ways to truncate their SQL DBs: https://stackoverflow.com/questions/41911906/how-to-clean-database-before-running-the-each-spec-file we could just add a db.collection.drop()..

Another thing they are doing is:

      try {
        await app.service('users').create(userInfo);
      } catch (error) {
        // Do nothing, it just means the user already exists and can be tested
      }

So ugly.

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.