Code Monkey home page Code Monkey logo

archive-explorer-node's Introduction

archive-explorer-node

Serve requests for the Archive Explorer project.

This is the back-end side of the Archive Explorer project. See archive-explorer-web for the front-end website.

Website is available in archive-explorer.com !

Foreword

None of the pages served to clients are server-side rendered. This server provides static access to the bundled React website, and gives access to an API developed with the Express framework.

API exposes multiple REST endpoints and a WebSocket powered by Socket.io.

This server needs a open mongoDB server to store user credentials and tweets/twitter users cache, internally opered by mongoose.

The whole project is developed in TypeScript.

Worker threads are used to dispatch tweet delete requests, so make sure you have a Node version that support the worker_threads module !

Supported Node versions are Node 10.5+ with --experimental-worker flag, or Node 12+ without flags.

Getting started for development

Clone repository and install dependencies with NPM.

git clone https://github.com/alkihis/archive-explorer-node.git
cd archive-explorer-node
npm i

Setting up constants

Some constants are not built-in, to provide security.

Twitter constants

You must have a working Twitter application in order to run server. This could be long to obtain, but I just can't share my own credentials.

Duplicate the file settings.sample.json and name it settings.json.

Set up inside the newly created file your Twitter application token (consumer key), the application secret key (consumer_secret key), and the callback after Sign in with Twitter login flow (localhost:3000/finalize should be fine for development, change it for production).

Public and private keys

This server use JWT (JSON Web Tokens) as token system. This kind of credentials requires a couple of public/private keys in order to sign tokens.

Create a .ssh folder in the directory root. Go to this directory. Create a public and private key with a passphrase.

All the created files will not be gitted to your fork or repo.

# Creating dir
mkdir .ssh
cd .ssh

# Generating private key (do not forget to enter a passphrase when asked)
ssh-keygen -t rsa -b 4096 -m PEM -f key_new.pem

# Generating public key
openssl rsa -in key_new.pem -pubout -outform PEM -out key_new

# Register the passphrase in the file "passphrase"
echo "my_choosen_passphrase" > passphrase

Project is ready !

Compiling and running project

You need to first compile the project in order to start the index.js file with Node. Make sure TypeScript npm package is installed globally.

tsc

Now, make sure the mongoDB server is running, then start the server:

node build/index.js -l <logLevel> -p <emitPort> -m <mongoDBPort>

Default values are:

  • -l info
  • -p 3128
  • -m 3281

You can ask for help with --help.

Deploy

By default, server will emit to port 443 (HTTPS). You just need to specify NODE_ENV=production env variable to build/index.js.

# You may need to be sudo to emit to port 443. 
# Otherwise, start in dev mode and use Nginx with reverse proxy.
NODE_ENV=production node build/index.js

Certificates should be in directory mentionned in settings.json's https_key_directory. It assume you will use Let's Encrypt.

archive-explorer-node's People

Contributors

alkihis avatar dependabot[bot] avatar rylixs avatar

Stargazers

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

Watchers

 avatar  avatar

archive-explorer-node's Issues

[BUG] Bad Decrypt Error When Signing JWT Token

First off, this project looks awesome. There were a couple things I needed to do in order to get it up and running that weren't in the README, but overall, it's great.

Nonetheless, here's is a screencap video of me running locally and getting the following error after logging in:

Screencap-Video.zip

Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
    at Sign.sign (internal/crypto/sig.js:84:29)
    at Object.sign (/Users/joemccan-mbp/Documents/archive-explorer-node/node_modules/jwa/index.js:152:45)
    at jwsSign (/Users/joemccan-mbp/Documents/archive-explorer-node/node_modules/jws/lib/sign-stream.js:32:24)
    at SignStream.sign (/Users/joemccan-mbp/Documents/archive-explorer-node/node_modules/jws/lib/sign-stream.js:58:21)
    at SignStream.<anonymous> (/Users/joemccan-mbp/Documents/archive-explorer-node/node_modules/jws/lib/sign-stream.js:46:12)
    at Object.onceWrapper (events.js:299:28)
    at DataStream.emit (events.js:210:5)
    at DataStream.<anonymous> (/Users/joemccan-mbp/Documents/archive-explorer-node/node_modules/jws/lib/data-stream.js:32:12)
    at processTicksAndRejections (internal/process/task_queues.js:75:11) {
  opensslErrorStack: [
    'error:0907B00D:PEM routines:PEM_read_bio_PrivateKey:ASN1 lib',
    'error:2306A075:PKCS12 routines:PKCS12_item_decrypt_d2i:pkcs12 pbe crypt error',
    'error:23077074:PKCS12 routines:PKCS12_pbe_crypt:pkcs12 cipherfinal error'
  ],
  library: 'digital envelope routines',
  function: 'EVP_DecryptFinal_ex',
  reason: 'bad decrypt',
  code: 'ERR_OSSL_EVP_BAD_DECRYPT'
}

It appears to be an error in decrypting something during the signing call.

Any help would be appreciated!

Node Version: 12.13.0
OS: MacOS: 10.14.6 Mojave

Token upgrades

Allow short life token (1 month f.e.), and allow clients to receive a new token that they must store.
Can be in users/credentials.

For now, token are long-lived (1 year, or more). Btw, token verifications must be made on server side to clean non-used tokens.

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.