Initialising the Kitten Server
Flowchart from the Technical Manual.
Text version
- initialise(options)
- Called by getInstanceAsync()?
- Throw: Server is a singleton
- Reset isBeingConstructedViaFactoryMethod
- Production: read pending update record, start the start deadline
- getDomainsAndPort(options), set kitten.domain and kitten.port
- Create Polka app (onError: ServerError.ts, onNoMatch: noMatchHandler())
- addAllMiddlewareToApp()
- Globals.initialise(domain, port)
- Create uploads directory and router (routerFor())
- InternalDatabase: initialise(), prepareForServer()
- Exit 1
- this.options: domains and domain redirects, settingsPath, domainToken, smallWebHostDomain
- Production: AppRepository and AutomaticUpdates singletons
- kitten._db.settings.id set?
- Store domain token and small web host domain, if not stored
- kitten.package = KittenPackage.getInstance(), check engines.kitten
- installNodeModulesIfNecessary(): npm ci or npm install
- AppDatabase.initialise(): kitten.db
- Exit 65 (dataError)
- Add Kittenās routes (web/š/ and web/š±/) through routeHandler()
- routes with the same method and pattern, or .connect.js or .connect.ts: Exit 65 (dataError)
- Add /uploads/:id/:download?
- Add /uploads/:id/:download?
- main.script.ts or main.script.js?
- Import it, await its default export with router (adds its routes and middleware)
- kitten.uploadLimits valid?
- Add the appās routes through routeHandler(), then the archives
- routes with the same method and pattern, or .connect.js or .connect.ts: Exit 65 (dataError)
- Routes under /š/, /š±/, or below /uploads/, or router routes at an app routeās URL?
- Routes under /š/, /š±/, or below /uploads/, or router routes at an app routeās URL?
- await https.createServer() with drainBeforeClose(pathRequestsOnly(app.handler))
- checkContinue handler, WebSocketServer (1 MB messages), upgrade and EADDRINUSE handlers
- server.listen(port)
- Once listening
- Set kitten.port, the placeās hosts (setPlaceDomains()), kitten.app.router, kitten.app.server
- Production: writeStartSeconds(), confirm pending update or prune, start automatic updates
- Print domain, source, data, identity link, REPL hint, status, app version, log sections
- With --open: open the browser
- Notify Catalyst if being deployed by it, unset the flag
- Production: schedule daily maintenance restart
- startKittenRepl()
- Exit 99 (restartRequest)