Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/defaultargs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// **defaultargs.coffee** when called on the argv object this
// module will create reasonable defaults for options not supplied,
// based on what information is provided.
import fs from 'node:fs'
import path from 'node:path'
import { randomBytes } from 'node:crypto'
import { fileURLToPath } from 'node:url'
Expand All @@ -26,6 +27,17 @@ export default argv => {
argv.root ||= __dirname
// the directory that contains all the packages that makeup the wiki
argv.packageDir ||= path.join(argv.root, '..')
// In a standard npm install, the wiki package.json is at packageDir/wiki/package.json.
// In development, fall back to the package.json in the current working directory.
if (!argv.packageFile) {
const installed = path.join(argv.packageDir, 'wiki', 'package.json')
try {
fs.accessSync(installed, fs.constants.F_OK)
argv.packageFile = installed
} catch {
argv.packageFile = path.join(process.cwd(), 'package.json')
}
}
argv.port ||= 3000
argv.home ||= 'welcome-visitors'
argv.data ||= path.join(getUserHome(), '.wiki') // see also cli
Expand Down Expand Up @@ -70,6 +82,7 @@ export default argv => {
// resolve all relative paths
argv.root = path.resolve(argv.root)
argv.packageDir = path.resolve(argv.packageDir)
argv.packageFile = path.resolve(argv.packageFile)
argv.data = path.resolve(argv.data)
argv.client = path.resolve(argv.client)
argv.db = path.resolve(argv.db)
Expand Down
16 changes: 16 additions & 0 deletions lib/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Federated Wiki : Node Server
*
* Custom error for page-not-found conditions.
* Allows callers to distinguish 404s from unexpected errors
* via instanceof check or the .status property.
*/

export class PageNotFoundError extends Error {
constructor(slug) {
super(`Page not found: ${slug}`)
this.name = 'PageNotFoundError'
this.status = 404
this.slug = slug
}
}
Loading