From 972c2ef86a59f0d90da9c11bcdfc9d7245379186 Mon Sep 17 00:00:00 2001 From: 8cy <50817549+8cy@users.noreply.github.com> Date: Wed, 15 Apr 2020 08:10:26 -0700 Subject: The Uwulapse, v6.0.0 - add webserver - fix servercount - formatting --- src/ws/ws.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/ws/ws.ts (limited to 'src/ws/ws.ts') diff --git a/src/ws/ws.ts b/src/ws/ws.ts new file mode 100644 index 0000000..08f9581 --- /dev/null +++ b/src/ws/ws.ts @@ -0,0 +1,54 @@ +import express from 'express'; +import hbs from 'express-handlebars'; +import bodyParser from 'body-parser'; +import path from 'path'; + +class WebSocket { + constructor(token, port, client) { + this.token = token; + this.client = client; + + this.app = express() + this.app.engine('hbs', hbs({ + extname: 'hbs', + defaultLayout: 'layout', + layoutsDir: __dirname + '/layouts' + })) + this.app.set('views', path.join(__dirname, 'views')) + this.app.set('view engine', 'hbs') + this.app.use(express.static(path.join(__dirname, 'public'))) + this.app.use(bodyParser.urlencoded({ extended: false })) + this.app.use(bodyParser.json()) + + this.registerRoots() + + this.server = this.app.listen(port, () => { + console.log(`Websocket listening on port ${this.server.address().port}`) + }) + } + + checkToken(_token) { + return (_token == this.token) + } + + // http://localhost:port?token=123456 + registerRoots() { + this.app.get('/', (req, res) => { + var _token = req.query.token + // if (!this.checkToken(_token)) { + // res.render('error', { + // title: 's1nical - Error', + // errtype: 'INVALID TOKEN' + // }) + // return + // } + + res.render('index', { + title: 'Uwufier - Status', + token: _token + }) + }) + } +} + +module.exports = WebSocket \ No newline at end of file -- cgit v1.2.3