-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
2,058 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = { | ||
env: { | ||
commonjs: true, | ||
es6: true, | ||
node: true | ||
}, | ||
extends: [ | ||
'standard' | ||
], | ||
globals: { | ||
Atomics: 'readonly', | ||
SharedArrayBuffer: 'readonly' | ||
}, | ||
parserOptions: { | ||
ecmaVersion: 2018 | ||
}, | ||
rules: { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,5 @@ dist | |
|
||
# TernJS port file | ||
.tern-port | ||
|
||
cert/ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** @type {import('express').Application} */ | ||
let appl | ||
|
||
/** @class */ | ||
class Rapp { | ||
constructor (root) { | ||
this.root = root | ||
} | ||
|
||
/** @param {reqandres} cb */ | ||
get (path, cb) { | ||
appl.get(this.root + path, cb) | ||
} | ||
|
||
/** @param {reqandres} cb */ | ||
put (path, cb) { | ||
appl.put(this.root + path, cb) | ||
} | ||
|
||
/** @param {reqandres} cb */ | ||
post (path, cb) { | ||
appl.post(this.root + path, cb) | ||
} | ||
|
||
/** @param {reqandres} cb */ | ||
all (path, cb) { | ||
appl.all(this.root + path, cb) | ||
} | ||
} | ||
|
||
module.exports = Rapp | ||
module.exports.reg = (app) => { appl = app } | ||
|
||
/** | ||
* @callback reqandres | ||
* @param {import('express').Request} req | ||
* @param {import('express').Response} res | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const port = process.env.hostPort || 8080 | ||
const sslPort = process.env.hostSSLPort || 8443 | ||
|
||
const cors = require('cors') | ||
const path = require('path').resolve() | ||
const http = require('http') | ||
const https = require('https') | ||
const express = require('express') | ||
const socketIo = require('socket.io') | ||
const { readFileSync, readdir, existsSync } = require('fs') | ||
|
||
const Rapp = require('./class/Rapp') | ||
|
||
const app = express() | ||
const ssl = { cert: readFileSync(path + '/cert/trinets-cert.pem'), key: readFileSync(path + '/cert/trinets-key.pem') } | ||
|
||
http.createServer(app).listen(port, () => { console.log('Non-SSL Server is now on http://localhost:' + port) }) | ||
https.createServer(ssl, app).listen(sslPort, () => { console.log('SSL Server is now on https://localhost:' + sslPort) }) | ||
|
||
const socket = socketIo(http) | ||
const ssocket = socketIo(https) | ||
|
||
Rapp.reg(app) | ||
|
||
app.get('/', () => { console.log(1) }) | ||
|
||
readdir(path + '/router', (err, routers) => { | ||
if (err) console.log(err) | ||
routers.forEach((router) => { | ||
if (!existsSync(path + '/router/' + router + '/index.js')) return | ||
router = require(path + '/router/' + router + '/index') | ||
|
||
if (router._cors) app.use(router._root, cors()) | ||
if (router._parse) { | ||
router._parse.forEach((p) => { | ||
switch (p) { | ||
case 'raw': app.use(router._root, express.raw()); break | ||
case 'json': app.use(router._root, express.json()); break | ||
case 'text': app.use(router._root, express.text()); break | ||
case 'form': app.use(router._root, express.urlencoded()); break | ||
} | ||
}) | ||
} | ||
|
||
const rapp = new Rapp(router._root) | ||
router.ready(rapp, router._socket ? { ws: socket, wss: ssocket } : undefined) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "hostframe", | ||
"version": "0.1.0", | ||
"description": "1:N express server for TriNet", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node index" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/tritiumNetworks/HostFrame.git" | ||
}, | ||
"author": "TriNet / PMH", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/tritiumNetworks/HostFrame/issues" | ||
}, | ||
"homepage": "https://github.com/tritiumNetworks/HostFrame#readme", | ||
"devDependencies": { | ||
"eslint": "^6.8.0", | ||
"eslint-config-standard": "^14.1.1", | ||
"eslint-plugin-import": "^2.20.2", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^4.2.1", | ||
"eslint-plugin-standard": "^4.0.1" | ||
}, | ||
"dependencies": { | ||
"cors": "^2.8.5", | ||
"express": "^4.17.1", | ||
"socket.io": "^2.3.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { _root: '/example', _socket: false, _cors: true, _parser: [], ready } | ||
|
||
function ready (app) { | ||
console.log('example is loaded') | ||
app.get('/', (_req, res) => res.send('example!')) | ||
} |
Oops, something went wrong.