You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

apin

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apin

fast lightweight rest-api builder

0.0.6
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

apin

fast lightweight rest-api builder

Apin Scripts

Add these to your package.json file.

"scripts": {
    "dev": "nodemon core/index.js",
    "dbd": "knex migrate:rollback --knexfile core/db/knexfile.js",
    "dbu": "knex migrate:latest --knexfile core/db/knexfile.js",
    "create_table": "knex migrate:make create_${npm_config_name} --knexfile core/db/knexfile.js",
    "create_seed": "knex seed:make ${npm_config_name} --knexfile core/db/knexfile.js",
    "seed": "knex seed:run --knexfile core/db/knexfile.js"
},

Knexfile

module.exports = {
    development: {
        client: 'pg',
        connection: {
            host: 'some-host',
            port: 'some-port',
            user: 'some-username',
            password: 'some-password',
            database: 'some-database'
        },
        migrations: {
            tableName: 'knex_migrations',
            directory: 'migrations'
        },
        seeds: {
            directory: 'seeds'
        },
    }
}

Apin Scripts

npm run create_table --name=users &&
npm run create_seed --name=01-users

Examples Migration

const tableName = 'users'

const schema = (table) => {
    table.increments()
    table.string('public_id').notNullable().unique()
    table.string('username').notNullable().unique()
    table.string('email').notNullable().unique()
    table.string('password').notNullable()
    table.boolean('is_verified').defaultTo(false)
    table.boolean('is_suspended').defaultTo(false)
    table.boolean('is_deactivated').defaultTo(false)
    table.timestamps(true, true)
}

exports.up = (knex) => knex.schema.createTable(tableName, schema)
exports.down = (knex) => knex.schema.dropTable(tableName)

Index File

global.apin = require('apin')()
const app = new (require('koa'))
const server = require('http').createServer(app.callback())
const bodyparser = require('koa-bodyparser')
const cors = require('kcors')
apin.io = require('socket.io')(server, {cors: {origin: '*'}})


app.use(apin.plugins.errorHandler)
app.use(bodyparser())
app.use(cors())
app.use(apin.router.routes())
app.use(apin.plugins.notFoundHandler)

server.listen(apin.config.server.port, () => {
    const host = require('url').format(apin.config.server)
    print('running at: %s', host)
})

Config File

module.exports = {
    server: {
        protocol: 'http',
        hostname: 'localhost',
        port:7000
    },
    jwt:{
        access:{
            key: 'some-scecret',
            options:{
                expiresIn: '10m',
                // algorithm: 'RS256'
            }
        },
        refresh:{
            key: 'some-other-scecret',
            options:{
                expiresIn: '30d',
                // algorithm: 'RS256'
            }
        },
    }
}

Keywords

rest-api

FAQs

Package last updated on 17 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts