Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc