Moved to correct folder and removed hard-coded URLs.

This commit is contained in:
David Ball 2024-05-24 14:18:06 -04:00
parent e8571edbd3
commit 5c11b90877
18 changed files with 55 additions and 21 deletions

View File

@ -59,7 +59,7 @@ Solr Test URL: [http://localhost:8983/](http://localhost:8983/)
Tika Test URL: [http://localhost:9998/](http://localhost:9998/) Tika Test URL: [http://localhost:9998/](http://localhost:9998/)
In case of trouble with accessing them from outside the localhost, please check and ensure the exposed Solr port is allowed through your firewall for the web server host to access. Please permit the Tika and the Solr port through your firewall in order to for any npm workers to request the plaintext for documents. In case of trouble with accessing them from outside the localhost, please check and ensure the exposed Solr port is allowed through your firewall for the web server host to access. Please permit the Tika and the Solr port through your firewall for any npm workers that need to request the plaintext for documents outside of Docker and submit them to the Solr search index.
# Installing ffmpeg # Installing ffmpeg

View File

@ -9,6 +9,7 @@ const ejs = require('ejs');
const helpers = require('../views/helpers/functions'); const helpers = require('../views/helpers/functions');
const search = require('../routes/search'); const search = require('../routes/search');
const fs = require('fs'); const fs = require('fs');
require('dotenv').config();
// const advancedSearch = require('../routes/advanced-search'); // const advancedSearch = require('../routes/advanced-search');
// Port number for HTTP server // Port number for HTTP server

View File

@ -35,6 +35,8 @@ services:
nm3clol: nm3clol:
build: ../nm3clol.Dockerfile build: ../nm3clol.Dockerfile
container_name: nm3clol container_name: nm3clol
environment:
- PORT=$APP_HTTP_LISTEN_PORT
ports: ports:
- "3000:3000" - "3000:3000"

View File

@ -4,6 +4,8 @@ services:
nm3clol: nm3clol:
build: ../nm3clol.Dockerfile build: ../nm3clol.Dockerfile
container_name: nm3clol container_name: nm3clol
environment:
- PORT=$APP_HTTP_LISTEN_PORT
ports: ports:
- "3000:3000" - "3000:3000"

View File

@ -4,5 +4,7 @@ services:
nm3clol: nm3clol:
build: ../nm3clol.Dockerfile build: ../nm3clol.Dockerfile
container_name: nm3clol container_name: nm3clol
environment:
- PORT=$APP_HTTP_LISTEN_PORT
ports: ports:
- "3000:3000" - "3000:3000"

View File

@ -8,17 +8,31 @@ const crypto = require('crypto');
const url = require('url') const url = require('url')
const { TikaClient } = require('./app/TikaClient/build'); const { TikaClient } = require('./app/TikaClient/build');
const { Readable, Writable } = require('stream'); const { Readable, Writable } = require('stream');
require('dotenv').config();
const relPathToFiles = './public'; const relPathToFiles = './public';
const baseUrl = 'https://no-moss-3-carbo-landfill-library.online'; // URL of the document to download and index
const tikaUrl = 'http://solr.services.cleveland.daball.me:9998'; // URL of the Tika instance const defaultSiteUrl = 'http://localhost';
const solrUrl = 'http://solr.services.cleveland.daball.me:8983/solr/my_core'; // URL of your Solr instance const defaultTikaUrl = 'http://tika:9998';
const solrVirginiaLawUrl = 'http://solr.services.cleveland.daball.me:8983/solr/va_code'; // URL of your Solr instance const defaultSolrDocsUrl = 'http://solr:8983/solr/nm3clol_core';
const defaultSolrLawUrl = 'http://solr:8983/solr/vacode_core';
const baseUrl = (process.env.SITE_URL||defaultSiteUrl).endsWith('/')
? (process.env.SITE_URL||defaultSiteUrl).substring(0, (process.env.SITE_URL||defaultSiteUrl).length - 2)
: process.env.SITE_URL||defaultSiteUrl; // URL of the document to download and index
const tikaUrl = (process.env.TIKA_URL||defaultTikaUrl).endsWith('/')
? (process.env.TIKA_URL||defaultTikaUrl).substring(0, (process.env.TIKA_URL||defaultTikaUrl).length - 2)
: process.env.TIKA_URL||defaultTikaUrl; // URL of the Tika instance
const solrDocsUrl = (process.env.SOLR_DOCS_URL||defaultSolrDocsUrl).endsWith('/')
? (process.env.SOLR_DOCS_URL||defaultSolrDocsUrl).substring(0, (process.env.SOLR_DOCS_URL||defaultSolrDocsUrl).length - 2)
: process.env.SOLR_DOCS_URL||defaultSolrDocsUrl; // URL of your Solr instance
const solrLawUrl = (process.env.SOLR_LAW_URL||defaultSolrLawUrl).endsWith('/')
? (process.env.SOLR_LAW_URL||defaultSolrLawUrl).substring(0, (process.env.SOLR_LAW_URL||defaultSolrLawUrl).length - 2)
: process.env.SOLR_LAW_URL||defaultSolrLawUrl; // URL of your Solr instance
// Task to clear out previous Solr data // Task to clear out previous Solr data
gulp.task('index:clear', async () => { gulp.task('index:clear', async () => {
await request({ await request({
uri: `${solrUrl}/update?commit=true`, uri: `${solrDocsUrl}/update?commit=true`,
method: 'POST', method: 'POST',
body: { delete: { query: '*:*' } }, // Delete all documents body: { delete: { query: '*:*' } }, // Delete all documents
json: true, json: true,
@ -27,7 +41,7 @@ gulp.task('index:clear', async () => {
gulp.task('dbfromsolr', async () => { gulp.task('dbfromsolr', async () => {
let docs = await request({ let docs = await request({
uri: `${solrUrl}/select`, uri: `${solrDocsUrl}/select`,
qs: { qs: {
q: '*:*', q: '*:*',
wt: 'json', wt: 'json',
@ -79,7 +93,7 @@ async function retrieveVirginiaLawMetadataFromSolr(url) {
// }); // });
const fl = encodeURIComponent("sha256sum, content_length"); const fl = encodeURIComponent("sha256sum, content_length");
const q = encodeURIComponent("id:")+"\""+encodeURIComponent(url)+"\"";//encodeURIComponent(`id:"${url}"`); const q = encodeURIComponent("id:")+"\""+encodeURIComponent(url)+"\"";//encodeURIComponent(`id:"${url}"`);
const uri = `${solrVirginiaLawUrl}/select?q=${q}&fl=${fl}`; const uri = `${solrLawUrl}/select?q=${q}&fl=${fl}`;
const response = await request({ uri: `${uri}`, json: true }); const response = await request({ uri: `${uri}`, json: true });
return response && response.response && response.response.docs && response.response.docs[0]; return response && response.response && response.response.docs && response.response.docs[0];
} }
@ -92,7 +106,7 @@ async function retrieveMetadataFromSolr(url) {
// }); // });
const fl = encodeURIComponent("sha256sum, content_length"); const fl = encodeURIComponent("sha256sum, content_length");
const q = encodeURIComponent("id:")+"\""+encodeURIComponent(url)+"\"";//encodeURIComponent(`id:"${url}"`); const q = encodeURIComponent("id:")+"\""+encodeURIComponent(url)+"\"";//encodeURIComponent(`id:"${url}"`);
const uri = `${solrUrl}/select?q=${q}&fl=${fl}`; const uri = `${solrDocsUrl}/select?q=${q}&fl=${fl}`;
const response = await request({ uri: `${uri}`, json: true }); const response = await request({ uri: `${uri}`, json: true });
return response && response.response && response.response.docs && response.response.docs[0]; return response && response.response && response.response.docs && response.response.docs[0];
} }
@ -101,7 +115,7 @@ async function indexDocumentInSolr(document) {
try { try {
// Send document to Solr using the Solr REST API or a Solr client library // Send document to Solr using the Solr REST API or a Solr client library
// Example code to send document using Axios: // Example code to send document using Axios:
await axios.post(solrUrl + '/update/json/docs', document, { await axios.post(solrDocsUrl + '/update/json/docs', document, {
params: { params: {
commit: true, // Commit changes immediately commit: true, // Commit changes immediately
}, },
@ -115,7 +129,7 @@ async function indexLawDocumentInSolr(document) {
try { try {
// Send document to Solr using the Solr REST API or a Solr client library // Send document to Solr using the Solr REST API or a Solr client library
// Example code to send document using Axios: // Example code to send document using Axios:
await axios.post(solrVirginiaLawUrl + '/update/json/docs', document, { await axios.post(solrLawUrl + '/update/json/docs', document, {
params: { params: {
commit: true, // Commit changes immediately commit: true, // Commit changes immediately
}, },
@ -168,7 +182,7 @@ gulp.task('index:laws', async () => {
const fileFullPath = path.join(cwd, file); const fileFullPath = path.join(cwd, file);
const url = `https://no-moss-3-carbo-landfill-library.online/${file.replaceAll(path.sep, '/')}`; const url = `${baseUrl}/${file.replaceAll(path.sep, '/')}`;
console.log('URL: ' + url); console.log('URL: ' + url);
// Retrieve metadata of the file from Solr (if it exists) // Retrieve metadata of the file from Solr (if it exists)
@ -267,7 +281,7 @@ gulp.task('index:docs', async () => {
const fileFullPath = path.join(cwd, file); const fileFullPath = path.join(cwd, file);
let url = `https://no-moss-3-carbo-landfill-library.online/${file.replaceAll(path.sep, '/')}`; let url = `${baseUrl}/${file.replaceAll(path.sep, '/')}`;
console.log('URL: ' + url); console.log('URL: ' + url);
// Retrieve metadata of the file from Solr (if it exists) // Retrieve metadata of the file from Solr (if it exists)

12
package-lock.json generated
View File

@ -13,6 +13,7 @@
"bytes": "3.0.0", "bytes": "3.0.0",
"cheerio": "^1.0.0-rc.12", "cheerio": "^1.0.0-rc.12",
"content-disposition": "0.5.2", "content-disposition": "0.5.2",
"dotenv": "^16.4.5",
"ejs": "^3.1.9", "ejs": "^3.1.9",
"express": "^4.18.3", "express": "^4.18.3",
"fast-url-parser": "1.1.3", "fast-url-parser": "1.1.3",
@ -5444,6 +5445,17 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/dotenv": {
"version": "16.4.5",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
"integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/duplexer": { "node_modules/duplexer": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.2.tgz", "resolved": "https://registry.npmjs.org/duplexer/-/duplexer-0.1.2.tgz",

View File

@ -20,6 +20,7 @@
"bytes": "3.0.0", "bytes": "3.0.0",
"cheerio": "^1.0.0-rc.12", "cheerio": "^1.0.0-rc.12",
"content-disposition": "0.5.2", "content-disposition": "0.5.2",
"dotenv": "^16.4.5",
"ejs": "^3.1.9", "ejs": "^3.1.9",
"express": "^4.18.3", "express": "^4.18.3",
"fast-url-parser": "1.1.3", "fast-url-parser": "1.1.3",

View File

@ -2,7 +2,7 @@ const express = require('express');
const router = express.Router(); const router = express.Router();
const { parse, toString } = require('lucene'); const { parse, toString } = require('lucene');
const { createClient, Query } = require('solr-client'); const { createClient, Query } = require('solr-client');
const solrConfig = { host: 'solr.services.cleveland.daball.me', port: 8983, core: 'my_core' }; const solrConfig = { host: process.env.SOLR_DOCS_HOST||'solr', port: process.env.SOLR_DOCS_PORT||8983, core: process.env.SOLR_DOCS_CORE_NAME||'nm3clol_core' };
const helpers = require('../views/helpers/functions'); const helpers = require('../views/helpers/functions');
router.get('/', (req, res) => { router.get('/', (req, res) => {

View File

@ -19,7 +19,7 @@ const md = markdownit({
const moment = require('moment-timezone').tz.setDefault("UTC"); const moment = require('moment-timezone').tz.setDefault("UTC");
const getSiteName = () => { const getSiteName = () => {
return 'No Moss 3 Carbo Landfill Online Library'; return process.env.SITE_NAME||'No Moss 3 Carbo Landfill Online Library';
} }
const trimSlashes = ({path}) => { const trimSlashes = ({path}) => {
@ -89,7 +89,7 @@ const renderArchive = (html, paths) => {
// Header and Footer content // Header and Footer content
const headHeaderContent = ``; const headHeaderContent = ``;
const headFooterContent = ` const headFooterContent = `
<!-- Dynamically Inserted Code by No Moss 3 Carbo Landfill Online Library --> <!-- Dynamically Inserted Code by ${process.env.SITE_NAME||'No Moss 3 Carbo Landfill Online Library'} -->
<style> <style>
.__archived__content__, .__archived__content__ p { background-color: #f44336; color: #fff; font-size: 12pt; font-family: "Noto Serif", Times, "Times New Roman", serif; text-align: center; } .__archived__content__, .__archived__content__ p { background-color: #f44336; color: #fff; font-size: 12pt; font-family: "Noto Serif", Times, "Times New Roman", serif; text-align: center; }
.__archived__content__ h1 { font-family: "Cinzel Decorative", Verdana, Arial, sans-serif; color: #fff; font-weight: 700; font-size: 18pt; text-align: center; } .__archived__content__ h1 { font-family: "Cinzel Decorative", Verdana, Arial, sans-serif; color: #fff; font-weight: 700; font-size: 18pt; text-align: center; }
@ -125,9 +125,9 @@ const renderArchive = (html, paths) => {
<!-- End dynamically inserted code --> <!-- End dynamically inserted code -->
`; `;
const bodyHeaderContent = ` const bodyHeaderContent = `
<!-- Dynamically Inserted Code by No Moss 3 Carbo Landfill Online Library --> <!-- Dynamically Inserted Code by ${process.env.SITE_NAME||'No Moss 3 Carbo Landfill Online Library'} -->
<div class="__archived__content__"> <div class="__archived__content__">
<h1>No Moss 3 Carbo Landfill Online Library</h1> <h1>${process.env.SITE_NAME||'No Moss 3 Carbo Landfill Online Library'}</h1>
<h2>Archived Web Site</h2> <h2>Archived Web Site</h2>
<p> <p>
This is an archived version of the original website. Online features will not be functional. Do not submit any personal information to this archive. This is an archived version of the original website. Online features will not be functional. Do not submit any personal information to this archive.
@ -139,7 +139,7 @@ const renderArchive = (html, paths) => {
<!-- End dynamically inserted code --> <!-- End dynamically inserted code -->
`; `;
const bodyFooterContent = ` const bodyFooterContent = `
<!-- Dynamically Inserted Code by No Moss 3 Carbo Landfill Online Library --> <!-- Dynamically Inserted Code by ${process.env.SITE_NAME||'No Moss 3 Carbo Landfill Online Library'} -->
<div class="__archived__content__"> <div class="__archived__content__">
<p> <p>
This is an archived version of the original website. Online features will not be functional. Do not submit any personal information to this archive. This is an archived version of the original website. Online features will not be functional. Do not submit any personal information to this archive.

View File

@ -10,7 +10,7 @@
<main class="container"> <main class="container">
<header> <header>
<h1 class="mt-5" style="font-family: 'Covered By Your Grace'"> <h1 class="mt-5" style="font-family: 'Covered By Your Grace'">
<a href="/">No Moss 3 Carbo Landfill Online Library</a> <a href="/"><%=h.getSiteName()%></a>
<span class="separator">&rsaquo; </span> <span class="separator">&rsaquo; </span>
Search Error<% if ((typeof query != undefined) && query != '') { %> for <%- query %><% } %> Search Error<% if ((typeof query != undefined) && query != '') { %> for <%- query %><% } %>
</h1> </h1>

View File

@ -10,7 +10,7 @@
<main class="container"> <main class="container">
<header> <header>
<h1 class="mt-5" style="font-family: 'Covered By Your Grace'"> <h1 class="mt-5" style="font-family: 'Covered By Your Grace'">
<a href="/">No Moss 3 Carbo Landfill Online Library</a> <a href="/"><%=h.getSiteName()%></a>
<span class="separator">&rsaquo; </span> <span class="separator">&rsaquo; </span>
Search Results for <%- query %> Search Results for <%- query %>
</h1> </h1>