From a69b3b644a9275e43a3832ed9cf3ccfbda336189 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Fri, 13 Jul 2018 12:25:26 +0300 Subject: Add a list of endpoints to the landing page --- frontpage.html | 29 ----------------------------- index.js | 11 +++++++++-- package-lock.json | 7 ++++++- package.json | 3 ++- views/frontpage.ejs | 40 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 33 deletions(-) delete mode 100644 frontpage.html create mode 100644 views/frontpage.ejs diff --git a/frontpage.html b/frontpage.html deleted file mode 100644 index 8f69a19..0000000 --- a/frontpage.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - Welcome to faaslift! - - - - -

Welcome to faaslift!

-

- Get started by creating a new endpoint with the command line tool. - Check out the instructions from the README. -

- Styles partially borrowed from bettermotherfuckingwebsite.com. - - \ No newline at end of file diff --git a/index.js b/index.js index 2d8f5ba..69ece12 100644 --- a/index.js +++ b/index.js @@ -10,12 +10,19 @@ const db = require('monk')(process.env.MONGO_URL); const express = require('express'); const app = express(); +app.set('view engine', 'ejs'); +app.set('views', path.join(__dirname, 'views')); + const requireFromString = require('require-from-string'); const models = require('./models')(db); const {installPackagesFromDatabase} = require('./npm')(models); -app.get('/', (req, res) => { - res.sendFile(path.join(__dirname, '/frontpage.html')); +app.get('/', async (req, res) => { + const endpointObjects = await models.endpoints.find({}); + const endpoints = endpointObjects.map(e => e.name); + res.render('frontpage', { + endpoints + }); }); app.all('/:path*', async (req, res) => { diff --git a/package-lock.json b/package-lock.json index 1fa5547..23c1389 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "faaslift", - "version": "1.0.5", + "version": "1.0.7", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1001,6 +1001,11 @@ "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" }, + "ejs": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-2.6.1.tgz", + "integrity": "sha512-0xy4A/twfrRCnkhfk8ErDi5DqdAsAqeGxht4xkCUrsvhhbQNs7E+4jV0CN7+NKIY0aHE72+XvqtBIXzD31ZbXQ==" + }, "encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", diff --git a/package.json b/package.json index e11c0ce..0c9d4eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "faaslift", - "version": "1.0.7", + "version": "1.0.8", "description": "", "main": "index.js", "scripts": { @@ -13,6 +13,7 @@ "dependencies": { "chalk": "^2.4.1", "dotenv": "^6.0.0", + "ejs": "^2.6.1", "express": "^4.16.3", "intercept-stdout": "^0.1.2", "monk": "^6.0.6", diff --git a/views/frontpage.ejs b/views/frontpage.ejs new file mode 100644 index 0000000..4e76a99 --- /dev/null +++ b/views/frontpage.ejs @@ -0,0 +1,40 @@ + + + + Welcome to faaslift! + + + + +

Welcome to faaslift!

+

+ Get started by creating a new endpoint with the command line tool. + Check out the instructions from the README. +

+

Currently active endpoints

+ <% if (!locals.endpoints || locals.endpoints.length === 0) { %> + No endpoints active + <% } %> + + Styles partially borrowed from bettermotherfuckingwebsite.com. + + \ No newline at end of file -- cgit v1.3