2.0.0-beta.2 • Published 4 years ago

scale-armor v2.0.0-beta.2

Weekly downloads
5
License
GNU GPLv3
Repository
github
Last release
4 years ago

ScaleArmor

Easy and simple scalable node restful api framework

ScaleArmor runs on top of feathers.js and is still under development

Install

npm install scale-armor

Setup a basic application

Congigure your test environment

Create a directory config in your project and then create a new file called default.json

{
    "host": "localhost",
    "port": 3030
}

Create the first model and route

Create a new file model.ts

import { Model, MongoDbModel } from 'scale-armor';

export interface Person extends Model {
    name: string;
    age: number;
    address: string;
    isEmployeed: boolean;
}
export class PersonModel extends MongoDbModel<Person> {
    constructor() {
        const collectionName = 'person';
        super(collectionName);
    }
}

Then create a new file route.ts

import { Routing, CRUDMethods, Method } from 'scale-armor';
import { PersonModel } from './model';

@CRUDMethods('/person', PersonModel)
export class MyRoutes extends Routing {
    constructor() {
        const routePath = '/api';
        super(routePath);
    }

    @Routing.Find('/status')
    public async status() {
        return 'ok';
    }
}

Wrap up everything

Finally create the file index.ts and wrap everything together

import { ScaleArmorServerlet } from 'scale-armor';
import { MyRoutes } from './route';

const serverlet = new ScaleArmorServerlet();
serverlet.setup()
    .installRoutingProvider(new MyRoutes())
    .middleware();
const app = serverlet.app;

const port = app.get('port');
const server = app.listen(port);

process.on('unhandledRejection', (reason, p) => {
    console.error('Unhandled Rejection at: Promise ', p, reason);
});

server.on('listening', () => {
    console.info('Feathers application started on http://%s:%d', app.get('host'), port);
});

Authentication

Set the Token secret

In any file before start your application set the token secret

import { Token } from 'scale-armor';

const secret = 'your super secret string'
Token.registerJwtSecret(secret);

Apply the auth hook

In any route add a before property

import { Routing, CRUDMethods, Method } from 'scale-armor';
import { PersonModel } from './model';

@CRUDMethods('/person', PersonModel)
export class MyRoutes extends Routing {
    private authRoutes = new AuthRoutes();
    protected before: ServiceHookFunction;
    constructor() {
        const routePath = '/api';
        super(routePath);

        this.before = this.authRoutes.getAuthHook(UserAccessType.Admin);
    }

    @Routing.Find('/status')
    public async status() {
        return 'ok';
    }
}
2.0.0-beta.2

4 years ago

2.0.0-beta.1

4 years ago

2.0.0-beta.0

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago