From 66829ceba5b1854bcec99cef9b39fafdc17c08e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Mass=C3=A9?= Date: Tue, 6 Jun 2017 13:27:29 +0200 Subject: [PATCH] initial commit --- .gitignore | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ .npmignore | 2 ++ LICENSE | 21 +++++++++++++++++ package.json | 14 ++++++++++++ server.js | 34 ++++++++++++++++++++++++++++ views/index.html | 56 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 186 insertions(+) create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 LICENSE create mode 100644 package.json create mode 100644 server.js create mode 100644 views/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..764f948 --- /dev/null +++ b/.gitignore @@ -0,0 +1,59 @@ + Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..c433e2a --- /dev/null +++ b/.npmignore @@ -0,0 +1,2 @@ +doc +LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3153fe0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Nicolas MASSE + +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. diff --git a/package.json b/package.json new file mode 100644 index 0000000..3ec2885 --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "openshift-demo-nodejs-front", + "version": "0.1.0", + "description": "An OpenShift Demo app running on NodeJS", + "main": "server.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Nicolas MASSE", + "license": "MIT", + "dependencies": { + "express": "latest" + } +} diff --git a/server.js b/server.js new file mode 100644 index 0000000..e7703d0 --- /dev/null +++ b/server.js @@ -0,0 +1,34 @@ +var express = require("express"); +var app = express(); +var router = express.Router(); +var port = 8080; + +var color = "red"; + +router.use(function (req,res,next) { + next(); + console.log("%s %s => %i", req.method, req.originalUrl, res.statusCode); +}); + +router.get("/",function(req,res){ + res.sendFile(__dirname + '/views/index.html'); +}); + +router.get("/info",function(req,res){ + var response = { + color: color, + podName: process.env["HOSTNAME"], + }; + res.type('application/json').send(JSON.stringify(response)); +}); + + +app.use("/",router); + +app.use("*",function(req,res){ + res.status(404).send("Not found"); +}); + +app.listen(port,function(){ + console.log("Live at Port %i", port); +}); diff --git a/views/index.html b/views/index.html new file mode 100644 index 0000000..435e47b --- /dev/null +++ b/views/index.html @@ -0,0 +1,56 @@ + + + + + OpenShift Demo + + + + + +
+
+ Hello from unknown ! +
+
+ +