mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 09:45:37 -04:00
added statusRouter.ts
Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
fd57ed19c2
commit
d4dc9a4046
1 changed files with 20 additions and 23 deletions
|
@ -1,20 +1,15 @@
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import { config } from '../config'
|
import { config } from '../config'
|
||||||
|
import { Router } from 'express'
|
||||||
|
import { errors } from '../errors'
|
||||||
|
import { realtime } from '../realtime'
|
||||||
|
import { Temp } from '../models'
|
||||||
|
import { logger } from '../logger'
|
||||||
|
import { urlencodedParser } from './utils'
|
||||||
|
|
||||||
const Router = require('express').Router
|
const StatusRouter = Router()
|
||||||
|
|
||||||
const errors = require('../errors')
|
|
||||||
const realtime = require('../realtime')
|
|
||||||
const models = require('../models')
|
|
||||||
const logger = require('../logger')
|
|
||||||
|
|
||||||
const { urlencodedParser } = require('./utils')
|
|
||||||
|
|
||||||
const statusRouter = module.exports = Router()
|
|
||||||
|
|
||||||
// get status
|
// get status
|
||||||
statusRouter.get('/status', function (req, res, next) {
|
StatusRouter.get('/status', function (req, res, _) {
|
||||||
realtime.getStatus(function (data) {
|
realtime.getStatus(function (data) {
|
||||||
res.set({
|
res.set({
|
||||||
'Cache-Control': 'private', // only cache by client
|
'Cache-Control': 'private', // only cache by client
|
||||||
|
@ -25,16 +20,16 @@ statusRouter.get('/status', function (req, res, next) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
// get status
|
// get status
|
||||||
statusRouter.get('/temp', function (req, res) {
|
StatusRouter.get('/temp', function (req, res) {
|
||||||
var host = req.get('host')
|
const host = req.get('host')
|
||||||
if (config.allowOrigin.indexOf(host) === -1) {
|
if (config.allowOrigin.indexOf(host) === -1) {
|
||||||
errors.errorForbidden(res)
|
errors.errorForbidden(res)
|
||||||
} else {
|
} else {
|
||||||
var tempid = req.query.tempid
|
const tempid = req.query.tempid
|
||||||
if (!tempid) {
|
if (!tempid) {
|
||||||
errors.errorForbidden(res)
|
errors.errorForbidden(res)
|
||||||
} else {
|
} else {
|
||||||
models.Temp.findOne({
|
Temp.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: tempid
|
id: tempid
|
||||||
}
|
}
|
||||||
|
@ -60,17 +55,17 @@ statusRouter.get('/temp', function (req, res) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// post status
|
// post status
|
||||||
statusRouter.post('/temp', urlencodedParser, function (req, res) {
|
StatusRouter.post('/temp', urlencodedParser, function (req, res) {
|
||||||
var host = req.get('host')
|
const host = req.get('host')
|
||||||
if (config.allowOrigin.indexOf(host) === -1) {
|
if (config.allowOrigin.indexOf(host) === -1) {
|
||||||
errors.errorForbidden(res)
|
errors.errorForbidden(res)
|
||||||
} else {
|
} else {
|
||||||
var data = req.body.data
|
const data = req.body.data
|
||||||
if (!data) {
|
if (!data) {
|
||||||
errors.errorForbidden(res)
|
errors.errorForbidden(res)
|
||||||
} else {
|
} else {
|
||||||
logger.debug(`SERVER received temp from [${host}]: ${req.body.data}`)
|
logger.debug(`SERVER received temp from [${host}]: ${req.body.data}`)
|
||||||
models.Temp.create({
|
Temp.create({
|
||||||
data: data
|
data: data
|
||||||
}).then(function (temp) {
|
}).then(function (temp) {
|
||||||
if (temp) {
|
if (temp) {
|
||||||
|
@ -90,8 +85,8 @@ statusRouter.post('/temp', urlencodedParser, function (req, res) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
statusRouter.get('/config', function (req, res) {
|
StatusRouter.get('/config', function (req, res) {
|
||||||
var data = {
|
const data = {
|
||||||
domain: config.domain,
|
domain: config.domain,
|
||||||
urlpath: config.urlPath,
|
urlpath: config.urlPath,
|
||||||
debug: config.debug,
|
debug: config.debug,
|
||||||
|
@ -107,3 +102,5 @@ statusRouter.get('/config', function (req, res) {
|
||||||
})
|
})
|
||||||
res.render('../js/lib/common/constant.ejs', data)
|
res.render('../js/lib/common/constant.ejs', data)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export { StatusRouter }
|
Loading…
Add table
Add a link
Reference in a new issue