const Router = require('express').Router
var cors = require('cors')
const router = Router()

const bodyParser = require('body-parser')
const multer = require('multer')
const upload = multer({ dest: 'upload_tmp/' })

const _ck = require('../controller/ckeditorMonitor')
const _op = require('../controller/DirMonitor')
const _websocket = require('../controller/SocketMonitor')
const _proxy = require('../controller/ProxyMonitor')

router.use(bodyParser.json({ limit: '600mb' }))
router.use(bodyParser.urlencoded({ extended: true, limit: '600mb' }))
router.use(cors({
  origin: 'https://ehall2.ezijing.com/',
  allowedHeaders: 'Accept, Content-Type, Referer, Sec-Fetch-Dest, tenant, token, User-Agent',
  credentials: true
}))

/* 统一API接口 */
router.post('/api/ckeditor/img/upload', upload.any(), _ck.ckeditorUpload)
router.post('/api/websocket/send-msg', upload.any(), _websocket.sendMsg)
router.post('/api/dir/send-msg', upload.any(), _op.dirOperate)
router.use('/api/*', upload.any(), _proxy.agentProcessor())

module.exports = router
