Commit 78345a73 authored by Bryan Tong's avatar Bryan Tong

Merge branch 'master' into 'master'

Initial commit.

See merge request kado/kado-base!1
parents dc8096b4 77dde52b
{
"extends": ["standard"]
}
node_modules
.idea
/config.*.js
npm-debug.log
/.session.json
This diff is collapsed.
# kado-base
For more information on how to get started using this repository see
[this documentation](https://git.nullivex.com/kado/kado/blob/master/doc/guides/QuickStart.md)
## License
Kado Copyright (C) 2013-2020 Bryan Tong, NULLIVEX LLC. All rights reserved. Kado
is licensed under the Lesser GNU Public License version 3.0 or newer see
[LICENSE.md](./LICENSE.md) for a complete copy of applicable licenses.
'use strict'
/**
* Kado - High Quality JavaScript Libraries based on ES6+ <https://kado.org>
* Copyright © 2013-2020 Bryan Tong, NULLIVEX LLC. All rights reserved.
*
* This file is part of Kado.
*
* Kado is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kado is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kado. If not, see <https://www.gnu.org/licenses/>.
*/
const Cluster = require('kado/lib/Cluster')
const cluster = Cluster.getInstance()
const fs = require('kado/lib/FileSystem')
// start cluster when master or hand off to the worker
if (process.env.command !== 'session' && cluster.isMaster()) {
const ChildProcess = require('kado/lib/ChildProcess')
const child = new ChildProcess({
fork: { env: { command: 'session' } },
path: process.argv[1]
})
// set our master name
process.title = 'kado-web:master'
// watch these files and folders for restarts
cluster.timeout.watch = 500
cluster.watch(
fs.path.resolve(process.argv[1] + '.js'),
fs.path.join(__dirname, 'main/route')
)
// start child and cluster
child.start()
cluster.start()
// otherwise setup our session storage server
} else if (process.env.command === 'session') {
process.title = 'kado-web:session'
const Session = require('kado/lib/Session')
const saveFile = fs.path.join(__dirname, '.session.json')
const storage = new Session.SessionStorage({ saveFile: saveFile })
storage.restoreFromDisk()
storage.listen()
} else {
// declare our application
const Application = require('kado/lib/Application')
const HyperText = require('kado/lib/HyperText')
const Parser = require('kado/lib/Parser')
const Session = require('kado/lib/Session')
const ViewMustache = require('kado/lib/View').ViewMustache
const app = Application.getInstance()
app.setName('kado-web')
app.setVersion(require('./package').version)
// add an http server
const http = new HyperText.HyperTextServer()
app.http.addEngine('http', http.createServer(app.router))
// add a view engine
const viewFolder = fs.path.join(__dirname, 'main/views')
app.view.addEngine('mustache', new ViewMustache(viewFolder))
app.view.activateEngine('mustache')
// add a static server
const staticRoot = fs.path.join(__dirname, 'main/public')
app.use(HyperText.StaticServer.getMiddleware(staticRoot))
// add a query parser
app.use((req) => {
req.query = new URL(`http://localhost${req.url}`).searchParams
})
// add a session handler
app.use((req) => { req.cookie = Parser.cookie('' + req.headers.cookie) })
app.use(Session.getMiddleware({ store: new Session.SessionStoreLocal() }))
// install routes
const route = require('./main/route')
app.get('/', route.index)
// initiate communications with the master and startup
Cluster.child(
http.getEngine(),
'kado-web:worker',
() => { return app.start().then(() => { return app.listen() }) },
() => { return app.stop() }
)
}
html, body {
padding: 0;
margin: 0;
}
.topbar {
background: #f1f1f1;
border-bottom: 1px solid #333;
padding: 10px;
line-height: 50px;
}
.topbar a, .topbar a:visited {
font-size: 2em;
color: blue;
text-decoration: none;
}
.content {
padding: 0 20px;
}
.copyright {
border-top: 1px solid #ddd;
padding-top: 20px;
font-size: 0.9em;
}
.copyright>.support {
padding-bottom: 10px;
font-size: 1.2em;
}
.copyright small {
color: #999;
}
\ No newline at end of file
User-agent: *
Disallow:
'use strict'
/**
* Kado - High Quality JavaScript Libraries based on ES6+ <https://kado.org>
* Copyright © 2013-2020 Bryan Tong, NULLIVEX LLC. All rights reserved.
*
* This file is part of Kado.
*
* Kado is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Kado is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Kado. If not, see <https://www.gnu.org/licenses/>.
*/
exports.index = (req, res) => {
if (req.query.get('name')) req.session.set('name', req.query.get('name'))
res.render('index', { name: req.session.get('name') || 'Foo' })
}
<!doctype HTML>
<html lang="eng">
<head>
<title>Hello World</title>
<link type="text/css" rel="stylesheet" href="/css/style.css">
</head>
<body>
<div class="topbar">
<div class="brand">
<div><a href="/">Kado</a></div>
<div class="slogan">High Quality Javascript Libraries</div>
</div>
</div>
{{>header}}
<div class="content">
<h1>Hello {{name}}</h1>
<p>Hello World!!</p>
<p>I would like to take a moment here to bragg a little bit that Kado is
finally doing web server things without any help from our dependencies! Its
great to be complete at this level of quality!</p>
<h2>API Documentation</h2>
<p>Try setting the name on this page using <code>/?name=(Your Name)</code>.
EG: <code>http://localhost/?name=John</code></p>
<div class="copyright">
<div class="support">Please see <a href="https://kado.org">kado.org</a> for documentation and support.</div>
<div>&copy; 2013-2020 Bryan Tong, NULLIVEX LLC. All rights reserved.</div>
<small>This software is licensed under the Lesser GNU Public License Version 3 or above. Please see <a href="https://www.gnu.org/licenses/licenses.html">GNU.org</a> for more details and a full copy of the license.</small>
</div>
</div>
{{>footer}}
{
"name": "kado-web",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"kado": {
"version": "git+https://git.nullivex.com/kado/kado#859ad7ac68e62501887be0af236c2a5f74216095",
"from": "git+https://git.nullivex.com/kado/kado"
},
"mustache": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/mustache/-/mustache-4.0.0.tgz",
"integrity": "sha512-FJgjyX/IVkbXBXYUwH+OYwQKqWpFPLaLVESd70yHjSDunwzV2hZOoTBvPf4KLoxesUzzyfTH6F784Uqd7Wm5yA=="
}
}
}
{
"author": "Kado <support@kado.org>",
"name": "kado-base",
"description": "Kado Base quick start package.",
"version": "1.0.0",
"homepage": "https://kado.org",
"license": "LGPL-3.0",
"repository": {
"type": "git",
"url": "https://git.nullivex.com/kado/kado-base.git"
},
"keywords": [
"kado",
"base",
"hello world"
],
"engines": {
"node": ">=10"
},
"main": "./app.js",
"dependencies": {
"kado": "git+https://git.nullivex.com/kado/kado",
"mustache": "^4.0.0"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment