项目作者: trevorjalt

项目描述 :
fluent Api
高级语言: JavaScript
项目地址: git://github.com/trevorjalt/fluent-api.git
创建时间: 2020-11-10T07:43:44Z
项目社区:https://github.com/trevorjalt/fluent-api

开源协议:

下载


fluent Api

Welcome to fluent, an app where you can practice learning a language with the spaced reptition revision technique.

fluent Api is the backend for fluent. To see fluent in action, check out fluent.

The fluent frontend can be found at: fluent-client

fluent supports the creation of your own user account. If you’d like to see it in action before signing up, use the demo account details below.

demo account details

  • username: admin
  • password: pass

what is spaced repetition?

Spaced repetition is a learning technique which exploits the psychological spacing effect. Within fluent, this means that words that you translate correctly will pop up with increasingly less frequency with consecutive correct answers. Conversely, get a word wrong and that word will begin to pop up more frequently.

table of contents.

the tech.

backend.

  • Node and Express
    • Authentication via JWT
    • RESTful Api
  • Testing
    • Supertest (integration)
    • Mocha and Chai (unit)
  • Database
    • Postgres
    • Knex.js - SQL wrapper

production.

Deployed via Heroku

setup.

requirements.

  • Postgres v8.5.1
  • Node v15.11.0

local setup.

Clone this repository to your local machine

  1. git clone https://github.com/trevorjalt/fluent-api fluent-api

Change directory into the cloned repository

  1. cd fluent-api

Make a fresh start of the git history for this project

  1. rm -rf .git && git init

Install the node dependencies

  1. npm install

Start the Postgres server

  1. pg_ctl start

Create the development user

  1. createuser -Pw --interactive

Type kakarot for the name of the role to add

Select y when asked if the user should be a super user

Press return (enter) for no password

Create the development databases

  1. createdb -U kakarot fluent && createdb -U kakarot fluent-test

Create a .env file in the project root, and include the following:

  1. NODE_ENV=development
  2. PORT=8000
  3. TZ='UTC'
  4. MIGRATION_DB_HOST=127.0.0.1
  5. MIGRATION_DB_PORT=5432
  6. MIGRATION_DB_NAME=fluent-test
  7. MIGRATION_DB_USER=kakarot
  8. MIGRATION_DB_PASS=
  9. DB_URL="postgresql://kakarot@localhost/fluent"
  10. TEST_DB_URL="postgresql://kakarot@localhost/fluent-test"
  11. JWT_SECRET="spaced-repetition-jwt-secret"

Run the migrations for the development test database

  1. npm run migrate:test

Update the following in the .env

  1. MIGRATION_DB_NAME=fluent

Run the migrations for the development database

  1. npm run migrate

Seed the development database

  1. psql -U kakarot -d fluent -f ./seeds/seed.tables.sql

quick start scripts.

Run the fluent tests

  1. npm t

Start the application

  1. npm start

Start nodemon for the application

  1. npm run dev

endpoints.

overview.

  • endpoints
    • /api/user
    • /api/auth
    • /api/language
    • /api/language/head
    • /api/language/guess

authentication.

fluent is supported by JWT authentication. A valid username and password must be posted to the /api/auth/token/ endpoint. This will return a bearer token that must be included in the header for all protected endpoints. To create a valid user, see /api/user/

public endpoints.

/api/user/

  • POST

request body requires:

  1. {
  2. name: '',
  3. username: '',
  4. password: ''
  5. }

/api/auth/token

  • POST

request body requires:

  1. {
  2. username: '',
  3. password: ''
  4. }

protected endpoints.

/api/language

  • GET

Header must include a JWT Token

request body requires

  1. {
  2. language_id: [number],
  3. user_id: [number]
  4. }

/api/language/head

  • GET

Header must include a JWT Token

request body requires

  1. {
  2. language_id: [number]
  3. }

/api/language/guess

  • POST

Header must include a JWT Token

request body requires:

  1. {
  2. guess: ''
  3. }

lets get fluent.