Skip to content

Commit

Permalink
Sync commands
Browse files Browse the repository at this point in the history
Signed-off-by: Reece Dunham <me@rdil.rocks>
  • Loading branch information
RDIL committed Feb 7, 2020
1 parent 0c09b8d commit 0ea5b67
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "static-server-rdil",
"version": "1.7.0",
"version": "1.8.0",
"description": "Static web server",
"homepage": "https://github.com/rdilweb/static-server",
"bin": {
"static-server": "./src/index.js"
"static-server-rdil": "./src/index.js"
},
"keywords": [
"server",
Expand Down
3 changes: 1 addition & 2 deletions source/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
* Get response headers.
*
* @param {boolean} enhancedSecurity Should enhanced security be applied?
* @param {string} mimetype The mime-type of the requested file.
* @default
* @param {string} mimetype The mime-type of the requested file.
*/
export default (enhancedSecurity, mimetype) => {
return !enhancedSecurity
Expand Down
15 changes: 14 additions & 1 deletion source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@ import handle from "./serverHandling"

/**
* The arguments passed via command line.
*
* @constant
* @readonly
*/
const argv = process.argv

/**
* The port that the server will run on.
*
* @default 3000
*/
let port = 3000

/**
* The root directory the server will serve.
*
* @default process.cwd
*/
let root = process.cwd()

Expand All @@ -30,11 +37,15 @@ let logRequests = true

/**
* If errors should be ignored.
*
* @default false
*/
let ignoreErrors = false

/**
* If emojis should be logged to the console.
*
* @default true
*/
let emojis = true

Expand All @@ -53,8 +64,10 @@ let renderMarkdown = true
*/
const emote = emojis ? emojify(":star:") : "!"

/**
* Manual argument parsing.
*/
argv.forEach(arg => {
// basic argument parsing
if (arg == "--help") {
help()
} else if (arg == "--port") {
Expand Down
17 changes: 15 additions & 2 deletions source/serverHandling.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import getHeaders from "./headers"
import markdown from "./markdownRendering"

/**
* Handle file request.
* Handle general request.
*
* @param {string} filePath The path requested.
* @param {http.ServerResponse} response The response object.
Expand Down Expand Up @@ -59,12 +59,19 @@ export default function handle(
if (!ignoreErrors) {
console.log(chalk`
{bgGray Internal Server Error: ${e}}
`)
`
)
}
}
}

/**
* Handle Markdown request.
* This will be called by the handle function,
* with all needed context.
*
* @see handle
*
* @param {http.ServerResponse} response
* @param {boolean} enhancedSecurity
* @param {string} filePath
Expand All @@ -78,6 +85,12 @@ let handleMarkdown = (response, enhancedSecurity, filePath) => {
}

/**
* Handle a request for a real, existing file.
* This will be called by the handle function,
* with all the needed context.
*
* @see handle
*
* @param {http.ServerResponse} response
* @param {string} fileExtension
* @param {boolean} enhancedSecurity
Expand Down
2 changes: 2 additions & 0 deletions source/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Please see {green https://docs.rdil.rocks/libraries/static-server-rdil/} for doc
*
* @param {Array<Any>} array The array.
* @param {Any} currentItem The item before the targeted item.
*
* @returns The next item in the array
*/
export let getNextItemInArray = (array, currentItem) => {
return array[array.indexOf(currentItem) + 1]
Expand Down

0 comments on commit 0ea5b67

Please sign in to comment.