From 72c68f4108f20185a7bc80b4f9624f3b9f2a3dc2 Mon Sep 17 00:00:00 2001 From: Ryan Lelek Date: Mon, 29 Apr 2024 23:02:30 -0500 Subject: [PATCH] Edit: Rename files --- .../workflows/{docker-image.yml => docker.ci.yml} | 2 +- .../{docker-release.yml => docker.release.yml} | 0 .github/workflows/{node.js.yml => nodejs.ci.yml} | 0 app/core/contents.js | 2 +- app/core/page.js | 2 +- app/core/search.js | 2 +- .../{contentProcessors.js => content_processors.js} | 0 app/index.js | 13 ++++++------- ...ys_authenticate.js => always_authenticate.mw.js} | 0 .../{authenticate.js => authenticate.mw.js} | 0 ...ead_access.js => authenticate_read_access.mw.js} | 4 ++-- .../{error_handler.js => error_handler.mw.js} | 4 ++-- app/middleware/{oauth2.js => oauth2.mw.js} | 4 +--- app/routes/sitemap.route.js | 2 +- app/routes/wildcard.route.js | 2 +- content/pages/tutorials/google-oauth-setup.md | 8 ++++---- server.js | 6 +----- test/functions.test.js | 2 +- test/raneto-core.test.js | 2 +- 19 files changed, 24 insertions(+), 31 deletions(-) rename .github/workflows/{docker-image.yml => docker.ci.yml} (98%) rename .github/workflows/{docker-release.yml => docker.release.yml} (100%) rename .github/workflows/{node.js.yml => nodejs.ci.yml} (100%) rename app/functions/{contentProcessors.js => content_processors.js} (100%) rename app/middleware/{always_authenticate.js => always_authenticate.mw.js} (100%) rename app/middleware/{authenticate.js => authenticate.mw.js} (100%) rename app/middleware/{authenticate_read_access.js => authenticate_read_access.mw.js} (83%) rename app/middleware/{error_handler.js => error_handler.mw.js} (86%) rename app/middleware/{oauth2.js => oauth2.mw.js} (99%) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker.ci.yml similarity index 98% rename from .github/workflows/docker-image.yml rename to .github/workflows/docker.ci.yml index c8cb6e95..4ec72bfc 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker.ci.yml @@ -1,7 +1,7 @@ --- # https://docs.github.com/en/actions/publishing-packages/publishing-docker-images -name: Docker Image CI +name: Docker CI on: push: branches: ["main"] diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker.release.yml similarity index 100% rename from .github/workflows/docker-release.yml rename to .github/workflows/docker.release.yml diff --git a/.github/workflows/node.js.yml b/.github/workflows/nodejs.ci.yml similarity index 100% rename from .github/workflows/node.js.yml rename to .github/workflows/nodejs.ci.yml diff --git a/app/core/contents.js b/app/core/contents.js index 33be5485..b3550d0a 100644 --- a/app/core/contents.js +++ b/app/core/contents.js @@ -5,7 +5,7 @@ import _ from 'underscore'; import _s from 'underscore.string'; import yaml from 'js-yaml'; import utils from './utils.js'; -import content_processors from '../functions/contentProcessors.js'; +import content_processors from '../functions/content_processors.js'; // TODO: Scan on start/change, not on every request async function handler(activePageSlug, config) { diff --git a/app/core/page.js b/app/core/page.js index de419144..293d248a 100644 --- a/app/core/page.js +++ b/app/core/page.js @@ -3,7 +3,7 @@ import fs from 'fs-extra'; import _s from 'underscore.string'; import { marked } from 'marked'; import utils from './utils.js'; -import content_processors from '../functions/contentProcessors.js'; +import content_processors from '../functions/content_processors.js'; async function handler(filePath, config) { const contentDir = utils.normalizeDir(path.normalize(config.content_dir)); diff --git a/app/core/search.js b/app/core/search.js index bc07878b..41784c80 100644 --- a/app/core/search.js +++ b/app/core/search.js @@ -1,6 +1,6 @@ import path from 'node:path'; import { glob } from 'glob'; -import content_processors from '../functions/contentProcessors.js'; +import content_processors from '../functions/content_processors.js'; import utils from './utils.js'; import page_handler from './page.js'; import lunr from './lunr.js'; diff --git a/app/functions/contentProcessors.js b/app/functions/content_processors.js similarity index 100% rename from app/functions/contentProcessors.js rename to app/functions/content_processors.js diff --git a/app/index.js b/app/index.js index ceee998d..d685c229 100644 --- a/app/index.js +++ b/app/index.js @@ -9,11 +9,11 @@ import hogan from 'hogan-express'; import session from 'express-session'; import passport from 'passport'; import language_load from './core/language.js'; -import mw_authenticate from './middleware/authenticate.js'; -import mw_always_auth from './middleware/always_authenticate.js'; -import mw_auth_readonly from './middleware/authenticate_read_access.js'; -import mw_error_handler from './middleware/error_handler.js'; -import mw_oauth2 from './middleware/oauth2.js'; +import mw_authenticate from './middleware/authenticate.mw.js'; +import mw_always_auth from './middleware/always_authenticate.mw.js'; +import mw_auth_readonly from './middleware/authenticate_read_access.mw.js'; +import mw_error_handler from './middleware/error_handler.mw.js'; +import mw_oauth2 from './middleware/oauth2.mw.js'; import route_login from './routes/login.route.js'; import route_login_page from './routes/login_page.route.js'; import route_logout from './routes/logout.route.js'; @@ -44,7 +44,6 @@ function initialize(config) { // Load Middleware const authenticate = mw_authenticate(config); const always_authenticate = mw_always_auth(config); - const authenticate_read_access = mw_auth_readonly(config); const error_handler = mw_error_handler(config); // Load Multiple-Use Pages @@ -118,7 +117,7 @@ function initialize(config) { saveUninitialized: false, }), ); - app.use(authenticate_read_access); + app.use(mw_auth_readonly(config)); // OAuth2 if (config.googleoauth === true) { app.use(passport.initialize()); diff --git a/app/middleware/always_authenticate.js b/app/middleware/always_authenticate.mw.js similarity index 100% rename from app/middleware/always_authenticate.js rename to app/middleware/always_authenticate.mw.js diff --git a/app/middleware/authenticate.js b/app/middleware/authenticate.mw.js similarity index 100% rename from app/middleware/authenticate.js rename to app/middleware/authenticate.mw.js diff --git a/app/middleware/authenticate_read_access.js b/app/middleware/authenticate_read_access.mw.js similarity index 83% rename from app/middleware/authenticate_read_access.js rename to app/middleware/authenticate_read_access.mw.js index 423b378a..62554e8f 100644 --- a/app/middleware/authenticate_read_access.js +++ b/app/middleware/authenticate_read_access.mw.js @@ -1,4 +1,4 @@ -function middleware_authenticate_read_access(config) { +function mw_authenticate_read_access(config) { if ( config.authentication === true && config.authentication_for_edit === false @@ -24,4 +24,4 @@ function middleware_authenticate_read_access(config) { } // Exports -export default middleware_authenticate_read_access; +export default mw_authenticate_read_access; diff --git a/app/middleware/error_handler.js b/app/middleware/error_handler.mw.js similarity index 86% rename from app/middleware/error_handler.js rename to app/middleware/error_handler.mw.js index 1f959b60..b69b4100 100644 --- a/app/middleware/error_handler.js +++ b/app/middleware/error_handler.mw.js @@ -1,5 +1,5 @@ // Error-Handling Middleware -function handler(config) { +function mw_error_handler(config) { return function (err, req, res) { const status = err.status || 500; @@ -19,4 +19,4 @@ function handler(config) { } // Exports -export default handler; +export default mw_error_handler; diff --git a/app/middleware/oauth2.js b/app/middleware/oauth2.mw.js similarity index 99% rename from app/middleware/oauth2.js rename to app/middleware/oauth2.mw.js index c3f8e31c..8020583d 100644 --- a/app/middleware/oauth2.js +++ b/app/middleware/oauth2.mw.js @@ -11,11 +11,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +// Modules import express from 'express'; - import fetch from 'node-fetch'; - -// [START setup] import passport from 'passport'; import { Strategy as GoogleStrategy } from 'passport-google-oauth20'; diff --git a/app/routes/sitemap.route.js b/app/routes/sitemap.route.js index e49c7d10..8b9f2b41 100644 --- a/app/routes/sitemap.route.js +++ b/app/routes/sitemap.route.js @@ -3,7 +3,7 @@ import path from 'node:path'; import fs from 'fs-extra'; import sm from 'sitemap'; import _ from 'underscore'; -import content_processors from '../functions/contentProcessors.js'; +import content_processors from '../functions/content_processors.js'; import utils from '../core/utils.js'; function route_sitemap(config) { diff --git a/app/routes/wildcard.route.js b/app/routes/wildcard.route.js index 516d9ad7..40b36f56 100644 --- a/app/routes/wildcard.route.js +++ b/app/routes/wildcard.route.js @@ -6,7 +6,7 @@ import { marked } from 'marked'; import toc from 'markdown-toc'; import build_nested_pages from '../functions/build_nested_pages.js'; import remove_image_content_directory from '../functions/remove_image_content_directory.js'; -import content_processors from '../functions/contentProcessors.js'; +import content_processors from '../functions/content_processors.js'; import contents_handler from '../core/contents.js'; import utils from '../core/utils.js'; diff --git a/content/pages/tutorials/google-oauth-setup.md b/content/pages/tutorials/google-oauth-setup.md index 052c68cb..7c1d12ba 100644 --- a/content/pages/tutorials/google-oauth-setup.md +++ b/content/pages/tutorials/google-oauth-setup.md @@ -28,7 +28,7 @@ Install the following packages: ### Editing the `app/index.js` file + Add passport: `import passport from 'passport';` just after raneto is required. -+ Add oauth2 middleware: `import oauth2 from './middleware/oauth2.js';` in the config block, just afer `error_handler.js` middleware. ++ Add oauth2 middleware: `import oauth2 from './middleware/oauth2.mw.js';` in the config block, just afer `error_handler.mw.js` middleware. + Change `secret` to `secret:config.secret,` in the `// HTTP Authentication` section. + >>> Remove the rn-login route `app.post('/rn-login', route_login);` + >>> Remove the logout route: `app.get('/logout', route_logout);` @@ -78,7 +78,7 @@ else { } ``` -### Editing the `app/middleware/authenticate.js` file +### Editing the `app/middleware/authenticate.mw.js` file Change the `res.redirect(403, '/login');` line to be: ``` @@ -102,8 +102,8 @@ return res.render('login', { }); ``` -### Add the oauth2.js file -Create a new file `oauth2.js` in the `app/middleware` folder with the following content: +### Add the oauth2.mw.js file +Create a new file `oauth2.mw.js` in the `app/middleware` folder with the following content: ``` // Copyright 2015-2016, Google, Inc. diff --git a/server.js b/server.js index 6a4e78c6..05ee36c3 100755 --- a/server.js +++ b/server.js @@ -1,8 +1,5 @@ #!/usr/bin/env node -// Modules -import _debug from 'debug'; - // Here is where we load Raneto. // When you are in your own project repository, // Raneto should be installed via NPM and loaded as: @@ -18,7 +15,6 @@ import config from './config/config.js'; const app = raneto(config); // Load the HTTP Server -const debug = _debug('raneto'); const server = app.listen(app.get('port'), app.get('host'), () => { - debug(`Express HTTP server listening on port ${server.address().port}`); + console.log(`HTTP server listening on port ${server.address().port}`); }); diff --git a/test/functions.test.js b/test/functions.test.js index 895c795c..cb8c4e5a 100644 --- a/test/functions.test.js +++ b/test/functions.test.js @@ -3,7 +3,7 @@ import fs from 'node:fs'; import path from 'node:path'; import moment from 'moment'; import build_nested_pages from '../app/functions/build_nested_pages.js'; -import content_processors from '../app/functions/contentProcessors.js'; +import content_processors from '../app/functions/content_processors.js'; import contents_handler from '../app/core/contents.js'; import utils from '../app/core/utils.js'; diff --git a/test/raneto-core.test.js b/test/raneto-core.test.js index d429c2e0..e5596a7d 100644 --- a/test/raneto-core.test.js +++ b/test/raneto-core.test.js @@ -1,5 +1,5 @@ import path from 'node:path'; -import content_processors from '../app/functions/contentProcessors.js'; +import content_processors from '../app/functions/content_processors.js'; import search_handler from '../app/core/search.js'; import page_handler from '../app/core/page.js'; import contents_handler from '../app/core/contents.js';