Commit 3e7c813c authored by Thomas Urban's avatar Thomas Urban

WIP for creating permanently running and configurable mockup-service

parent a1eba337
Pipeline #2105 passed with stage
in 31 seconds
......@@ -4,3 +4,6 @@
node_modules
npm-debug.log
debug.log
config/*.conf
!config/*.dist.conf
FROM node:lts-alpine
COPY ./ /app
RUN apk update && apk add nano && npm ci
VOLUME /app/config
EXPOSE 3000
ENTRYPOINT ["npm", "run", "start"]
/api/items ==> MSG
Content-Type: application/json
{"items":[]}
EOM
......@@ -5,6 +5,7 @@
"main": "index.js",
"private": false,
"scripts": {
"start": "node server.js",
"style": "eslint .",
"test": "mocha --ui=tdd --recursive test/**/*.spec.js"
},
......
#!/usr/bin/env node
/**
* (c) 2019 cepharum GmbH, Berlin, http://cepharum.de
*
* The MIT License (MIT)
*
* Copyright (c) 2019 cepharum GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @author: cepharum
*/
"use strict";
const Path = require( "path" );
const File = require( "fs" );
const ConfigFolder = Path.resolve( __dirname, "config" );
const Services = {
http: {
default: 80,
},
https: {
default: 443,
},
tcp: {},
udp: {},
};
/*
* Enumerate service definitions.
*/
File.readdirSync( ConfigFolder, { withFileTypes: true } )
.forEach( entry => {
if ( entry.isFile() ) {
const pattern = /^([^\s\d]+(?:\.[^\s\d]+)*)(?:\.(\d+))?\.conf$/.exec( entry.name );
if ( pattern ) {
const segments = pattern[1].split( "." );
switch ( segments[segments.length - 1] ) {
case "example" :
case "dist" :
break;
default : {
const service = segments[0];
if ( Services.hasOwnProperty( service ) ) {
const port = parseInt( pattern[2] ) || Services[service].default;
if ( port ) {
if ( !Services.hasOwnProperty( port ) ) {
Services[port] = {};
}
Services[port][segments.slice( 1 ).join( "." )] = File.readFileSync( Path.join( ConfigFolder, entry.name ), "utf8" );
}
}
}
}
}
}
} );
/*
* Create services.
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment