Archived
0
This commit is contained in:
2017-11-13 12:32:51 +03:00
parent c5a5387b45
commit 718fe9a454
5 changed files with 52 additions and 6 deletions

View File

@@ -1,9 +1,11 @@
/* --- IMPORTS -------------------------- */
const config = require('config');
const tracer = require('tracer');
const express = require('express');
const bodyParser = require('body-parser');
const concatStream = require('concat-stream');
const config = require('config');
const fs = require('fs');
const os = require('os');
@@ -11,6 +13,13 @@ const path = require('path');
/* --- SETUP ---------------------------- */
// Logger
global.logger = tracer.console({
level: config.get('logger.level'),
format: config.get('logger.format'),
dateformat: config.get('logger.datetime')
});
// Express
const app = express();
app.use((req, res, next) => {
@@ -42,6 +51,11 @@ function toOsPath(urlPath) {
/* --- ROUTING -------------------------- */
app.all('*', (req, res, next) => {
global.logger.trace('Path: %s | Method: %s', req.originalUrl, req.method);
next();
});
app.route(`/${config.get('maven.url')}/*`)
.get((req, res) => {
let osPath = toOsPath(req.path);
@@ -60,7 +74,7 @@ app.route(`/${config.get('maven.url')}/*`)
fs.writeFile(osPath, req.rawBody, (err) => {
if (err) {
console.error(err);
global.logger.error(err);
res.status(500).send();
} else {
res.status(200).send();
@@ -70,5 +84,7 @@ app.route(`/${config.get('maven.url')}/*`)
/* --- START APP ------------------------ */
console.info(`Start web server :: ${config.get('web.host')}:${config.get('web.port')}`);
app.listen(config.get('web.port'), config.get('web.host'));
const host = config.get('web.host'),
port = config.get('web.port')
global.logger.info('Start server :: %s:%s', host, port);
app.listen(port, host);