Skip to content

Latest commit

 

History

History
44 lines (33 loc) · 1.09 KB

application.md

File metadata and controls

44 lines (33 loc) · 1.09 KB

Dito.js Application

The Dito.js Application class inherits from the Koa Application class.

Normally, a simple Dito.js Server creates only one Application instance and exports it:

src/server/app.js:
import { Application } from '@ditojs/server'
import mount from 'koa-mount'
import serve from 'koa-static'
import config from '../config.js'
import * as models from './models/index.js'
import * as controllers from './controllers/index.js'

const app = new Application({
  config,
  models,
  controllers
})

// Static Assets:
app.use(mount('/assets', serve('assets')))

export default app

Then, in the application's main file, all it takes to start the server is the following statement:

src/server/index.js:
import app from './app/index.js'

app.execute()

Dito.js applications can register custom keywords and formats for JSON schema validation. In order to do so, a Validator instance needs to be provided.

See Validator and Model Properties for more information on JSON schema validation.