Merge branch 'dev-config' into dev
This commit is contained in:
22
config.js
22
config.js
@@ -1,22 +0,0 @@
|
||||
/* --- IMPORTS -------------------------- */
|
||||
|
||||
require('dotenv').config();
|
||||
|
||||
/* --- SETUP ---------------------------- */
|
||||
|
||||
let web = {
|
||||
host: process.env.W_HOST,
|
||||
port: process.env.W_PORT
|
||||
};
|
||||
|
||||
let maven = {
|
||||
// example(win): /User/admin/.micro-m2
|
||||
dir: process.env.MAVEN_DIR,
|
||||
// example: mvn
|
||||
url: process.env.MAVEN_ROOT_URL
|
||||
};
|
||||
|
||||
/* --- EXPORTS -------------------------- */
|
||||
|
||||
module.exports.web = web;
|
||||
module.exports.maven = maven;
|
||||
7
config/default.yml
Normal file
7
config/default.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
web:
|
||||
host: 127.0.0.1
|
||||
port: 8080
|
||||
|
||||
maven:
|
||||
dir: '/User/admin/.micro-m2'
|
||||
url: 'mvn'
|
||||
@@ -9,7 +9,8 @@
|
||||
"dependencies": {
|
||||
"body-parser": "^1.18.2",
|
||||
"concat-stream": "^1.6.0",
|
||||
"dotenv": "^4.0.0",
|
||||
"express": "^4.16.1"
|
||||
"config": "^1.28.1",
|
||||
"express": "^4.16.1",
|
||||
"js-yaml": "^3.10.0"
|
||||
}
|
||||
}
|
||||
|
||||
11
server.js
11
server.js
@@ -3,13 +3,12 @@
|
||||
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');
|
||||
const path = require('path');
|
||||
|
||||
const config = require('./config');
|
||||
|
||||
/* --- SETUP ---------------------------- */
|
||||
|
||||
// Express
|
||||
@@ -38,12 +37,12 @@ function mkdir(dir) {
|
||||
}
|
||||
|
||||
function toOsPath(urlPath) {
|
||||
return config.maven.dir + urlPath.substr(config.maven.url.length + 1);
|
||||
return config.get('maven.dir') + urlPath.substr(config.get('maven.url').length + 1);
|
||||
}
|
||||
|
||||
/* --- ROUTING -------------------------- */
|
||||
|
||||
app.route(`/${config.maven.url}/*`)
|
||||
app.route(`/${config.get('maven.url')}/*`)
|
||||
.get((req, res) => {
|
||||
let osPath = toOsPath(req.path);
|
||||
fs.exists(osPath, (value) => {
|
||||
@@ -71,5 +70,5 @@ app.route(`/${config.maven.url}/*`)
|
||||
|
||||
/* --- START APP ------------------------ */
|
||||
|
||||
console.info(`Start web server :: ${config.web.host}:${config.web.port}`);
|
||||
app.listen(config.web.port, config.web.host);
|
||||
console.info(`Start web server :: ${config.get('web.host')}:${config.get('web.port')}`);
|
||||
app.listen(config.get('web.port'), config.get('web.host'));
|
||||
|
||||
40
yarn.lock
40
yarn.lock
@@ -9,6 +9,12 @@ accepts@~1.3.4:
|
||||
mime-types "~2.1.16"
|
||||
negotiator "0.6.1"
|
||||
|
||||
argparse@^1.0.7:
|
||||
version "1.0.9"
|
||||
resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.9.tgz#73d83bc263f86e97f8cc4f6bae1b0e90a7d22c86"
|
||||
dependencies:
|
||||
sprintf-js "~1.0.2"
|
||||
|
||||
array-flatten@1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-1.1.1.tgz#9a5f699051b1e7073328f2a008968b64ea2955d2"
|
||||
@@ -40,6 +46,13 @@ concat-stream@^1.6.0:
|
||||
readable-stream "^2.2.2"
|
||||
typedarray "^0.0.6"
|
||||
|
||||
config@^1.28.1:
|
||||
version "1.28.1"
|
||||
resolved "https://registry.yarnpkg.com/config/-/config-1.28.1.tgz#7625d2a1e4c90f131d8a73347982d93c3873282d"
|
||||
dependencies:
|
||||
json5 "0.4.0"
|
||||
os-homedir "1.0.2"
|
||||
|
||||
content-disposition@0.5.2:
|
||||
version "0.5.2"
|
||||
resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.2.tgz#0cf68bb9ddf5f2be7961c3a85178cb85dba78cb4"
|
||||
@@ -74,10 +87,6 @@ destroy@~1.0.4:
|
||||
version "1.0.4"
|
||||
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
|
||||
|
||||
dotenv@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-4.0.0.tgz#864ef1379aced55ce6f95debecdce179f7a0cd1d"
|
||||
|
||||
ee-first@1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
|
||||
@@ -90,6 +99,10 @@ escape-html@~1.0.3:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
|
||||
|
||||
esprima@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804"
|
||||
|
||||
etag@~1.8.1:
|
||||
version "1.8.1"
|
||||
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
|
||||
@@ -174,6 +187,17 @@ isarray@~1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
|
||||
|
||||
js-yaml@^3.10.0:
|
||||
version "3.10.0"
|
||||
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.10.0.tgz#2e78441646bd4682e963f22b6e92823c309c62dc"
|
||||
dependencies:
|
||||
argparse "^1.0.7"
|
||||
esprima "^4.0.0"
|
||||
|
||||
json5@0.4.0:
|
||||
version "0.4.0"
|
||||
resolved "https://registry.yarnpkg.com/json5/-/json5-0.4.0.tgz#054352e4c4c80c86c0923877d449de176a732c8d"
|
||||
|
||||
media-typer@0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
|
||||
@@ -214,6 +238,10 @@ on-finished@~2.3.0:
|
||||
dependencies:
|
||||
ee-first "1.1.1"
|
||||
|
||||
os-homedir@1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3"
|
||||
|
||||
parseurl@~1.3.2:
|
||||
version "1.3.2"
|
||||
resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.2.tgz#fc289d4ed8993119460c156253262cdc8de65bf3"
|
||||
@@ -301,6 +329,10 @@ setprototypeof@1.1.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.1.0.tgz#d0bd85536887b6fe7c0d818cb962d9d91c54e656"
|
||||
|
||||
sprintf-js@~1.0.2:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
|
||||
|
||||
"statuses@>= 1.3.1 < 2", statuses@~1.3.1:
|
||||
version "1.3.1"
|
||||
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e"
|
||||
|
||||
Reference in New Issue
Block a user