Giter Site home page Giter Site logo

hexo-server's Introduction

hexo-server

Build Status NPM version Coverage Status

Server module for Hexo.

Installation

$ npm install hexo-server --save

Usage

$ hexo server
Option Description Default
-i, --ip Override the default server IP. :: when IPv6 is available, else 0.0.0.0 (note: in most systems, :: also binds to 0.0.0.0)
-p, --port Override the default port. 4000
-s, --static Only serve static files. false
-l, --log [format] Enable logger. Override log format. false
-o, --open Immediately open the server url in your default web browser. false

Options

server:
  port: 4000
  log: false
  ip: 0.0.0.0
  compress: false
  cache: false
  header: true
  serveStatic:
    extensions:
    - html
  • port: Server port
  • log: Display request info on the console. Always enabled in debug mode.
  • ip: Server IP
  • compress: Enable GZIP compression
  • cache: Enable cache for rendered content
    • This can speed up server response. However, any changes will no longer take effect in real time.
    • Suitable for production environment only.
  • header: Add X-Powered-By: Hexo header
  • serveStatic: Extra options passed to serve-static

License

MIT

hexo-server's People

Contributors

9662 avatar abernix avatar curbengh avatar d-sketon avatar demurgos avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar evancarroll avatar fabsenet avatar jlhwung avatar knpwrs avatar noahdragon avatar segayuu avatar sukkaw avatar thesadabc avatar tomap avatar tommy351 avatar uiolee avatar upupming avatar xiejiss avatar yoshinorin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hexo-server's Issues

Post with a timestamp in the future will not be visible even if defined time had past without restarting server

Environment Info

Node version(node -v):
v6.11.3

Your site _config.yml (Optional):
Related config:

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: false

Your theme _config.yml (Optional):
N/A

Hexo and Plugin version(npm ls --depth 0):
[email protected]

For BUG

  1. BUG description:
    If hexo is set not to show future posts, then if the server is started before the post become visible, the post will not be shown even if the timestamp had past.

When doing hexo g after the timestamp had past, the post can be generated properly in public folder.

  1. The way to reproduce
  • Configure hexo not to show post in future.
  • Start the hexo server.
  • Create a post that will become visible in future.
  • Refresh the page without restarting the server after the timestamp goes into past, the post will still not be visible.
  1. Log with hexo --debug
    N/A

Related

hexojs/hexo#188
hexojs/hexo#2776

hexo server hyperlink points at the wrong page

I created a new post using hexo s
but however even if i create more posts through it, they all seems to point at the same page, and does not do anything after hexo g
for example
image
image
any ideas how can i fix it?

NPM not updated

NPM version 0.0.4 doesn't have the open functionality added by @KenPowers . Please consider publishing the updated version.

Hexo s can't console the file changes

I don't know why I change the md file locally and the hexo s console page didn't change simultaneously after I refreshed my page.
Something went wrong?

Crash when callin hexo server -o

Hi,

I have the following crash when I call hexo server -o:

INFO  Hexo is running at http://localhost:4000. Press Ctrl+C to stop.
(node:23889) UnhandledPromiseRejectionWarning: Error: Expected a `target`
    at module.exports (/Users/thomas/Documents/hexo/tpi/node_modules/opn/index.js:9:25)
    at /Users/thomas/Documents/hexo/tpi/node_modules/hexo-server/lib/server.js:37:7
    at tryCatcher (/Users/thomas/Documents/hexo/tpi/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/thomas/Documents/hexo/tpi/node_modules/bluebird/js/release/promise.js:510:31)
    at Promise._settlePromise (/Users/thomas/Documents/hexo/tpi/node_modules/bluebird/js/release/promise.js:567:18)
    at Promise._settlePromise0 (/Users/thomas/Documents/hexo/tpi/node_modules/bluebird/js/release/promise.js:612:10)
    at Promise._settlePromises (/Users/thomas/Documents/hexo/tpi/node_modules/bluebird/js/release/promise.js:691:18)
    at Async._drainQueue (/Users/thomas/Documents/hexo/tpi/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/Users/thomas/Documents/hexo/tpi/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/Users/thomas/Documents/hexo/tpi/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:773:18)
    at tryOnImmediate (timers.js:734:5)
    at processImmediate [as _immediateCallback] (timers.js:711:5)
(node:23889) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:23889) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I believe it is due to this commit:
dd31ccb#diff-c945a46d13b34fcaff544d966cffcabaL30

You should do:
https://github.com/hexojs/hexo-server/blob/master/lib/server.js#L37
open(addrString)
instead of
open(addr)

Regards,

Thomas

Unix Domain Socked, Named Pipes and HTTPS

Hello, I would like to contribute to this project by adding support to unix domain socket, named pipes and https. It is something in the architecture that I would like to suggest. Instead of using ip address and port to listen, I would like to suggest using an url like http://localhost:4000, https://localhost:4000 or file://./path-to-unix-domain-socket-or-windows-named-pipe.

I am currently working on that feature. If you could check and give me some suggestions I would appreciate.

https://github.com/arthurafarias/hexo-server/commit/e903795e9d3516fea5a185ef4e6925de559d8dc1

Can hexo server be used in Javascript?

It seems that hexo-server is not a regular node module. It relies on hexo-inject.

I'd like to start an Hexo server in Javascript code. How can I achieve that without using shell / subprocess?

no --drafts option anymore?

I tried to use the --drafts option just like before but with hexo 3.0.0 it seems to have no effect. can it be brought back?

Query part of URL is not preserved across redirects

When serving a request for /some/path where the actual resource is /some/path/index.html, the server performs an HTTP 302 redirect to /some/path/, but in the process, it loses any query information the original URL might have had.

Recall that query parts may be used not just by the server but also by client-side Javascript.

Test case

  1. Have a resource such as /some/path/index.html
  2. Start hexo-server
  3. Request /some/path?id=test

Expected result

The user is redirected to /some/path/?id=test (assuming root is /).

Actual result

The user is redirected to /some/path/ and the query information is lost.

Custom mime type for extensionless files

Hello,

I'm looking to do hosting on S3 without extensions on URLs. What would be really nice here is a custom mime type for files with no extension, that way I can have my html pages created without an extension and just served normally.

The solution I've got currently is this, in lib/middlewares/route.js:
res.setHeader('Content-Type', extname ? mime.lookup(extname) : config.extensionless_mime_type || 'application/octet-stream');

and this in _config.yml:
extensionless_mime_type: 'text/html'

Would this be a suitable feature request and implementation? If so I can submit a pull request.

Cheers,
Matt

hexo-server can not detect my language support correctly

language: 
- zh-CN
- en

I have en.ymlandzh-CN.yml templates. I change my OS' language and browser's language to English. But the site under hexo-server still convert content of __() to simple Chinese. After I arranged en to the first, content of __() always display English no matter what language setting of OS and browser.

Does something I misunderstand?

Disable browser catching thorugh headers

The hexo server should have an ability to disable browser caching by adding headers like:

Cache-Control: no-cache, must-revalidate
Expires: Sat, 26 Jul 1997 05:00:00 GMT

Or something to that effect. Doesn't have to be so by default, it could be a config option.

This would avoid mistaking lack of some changes appearing after refresh as a problem with the generation phase.

Ignore themes Node_modules

While My Theme use babel & Webpack, run hexo server. It will Print (Like):

INFO  Deleted database.
INFO  Start processing
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Error: watch /home/a632079/Desktop/a632079/themes/aero-dual/node_modules/lodash/fp/F.js ENOSPC
    at _errnoException (util.js:1003:13)
    at FSWatcher.start (fs.js:1405:19)
    at Object.fs.watch (fs.js:1431:11)
    at createFsWatchInstance (/home/a632079/Desktop/a632079/node_modules/chokidar/lib/nodefs-handler.js:37:15)
    at setFsWatchListener (/home/a632079/Desktop/a632079/node_modules/chokidar/lib/nodefs-handler.js:80:15)
    at FSWatcher.NodeFsHandler._watchWithNodeFs (/home/a632079/Desktop/a632079/node_modules/chokidar/lib/nodefs-handler.js:228:14)
    at FSWatcher.NodeFsHandler._handleFile (/home/a632079/Desktop/a632079/node_modules/chokidar/lib/nodefs-handler.js:255:21)
    at FSWatcher.<anonymous> (/home/a632079/Desktop/a632079/node_modules/chokidar/lib/nodefs-handler.js:473:21)
    at FSReqWrap.oncomplete (fs.js:167:5)

To solve it,
I need to REMOVE node_modules dir.
Could you give a parameter to ignore this dir ?

config ip setting is not respected

In my config file I have following:

port: 4000
server_ip: 127.0.0.1

However hexo always starts on 0.0.0.0. For now I use --ip as a workaround, and I think it should be fixed.

hexo server not working

2017_10_30_11_28_48

After execute npm install, and then run the command hexo server, it not working! my package.json is:

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": "3.4.0"
  },
  "dependencies": {
    "hexo": "^3.4.0",
    "hexo-server": "^0.2.0",
    "hexo-deployer-git": "^0.3.1",
    "hexo-generator-archive": "^0.1.4",
    "hexo-generator-category": "^0.1.3",
    "hexo-generator-index": "^0.2.0",
    "hexo-generator-tag": "^0.2.0",
    "hexo-inject": "^1.0.0",
    "hexo-renderer-ejs": "^0.3.0",
    "hexo-renderer-marked": "^0.3.0",
    "hexo-renderer-mathjax": "^0.6.0",
    "hexo-renderer-stylus": "^0.3.1"
  }
}

EMFILE exception when watching on Win7

On my Window 7 system, the "hexo server" command will usually crash with the EMFILE error. I say usually because if I run "hexo clean && hexo server" enough times then it eventually works. Below is my cmd shell dump...

C:\Users\andjon\Source\janderland>hexo server --debug
02:16:47.479 DEBUG Hexo version: 3.2.0
02:16:47.479 DEBUG Working directory: ~\Source\janderland
02:16:47.572 DEBUG Config loaded: ~\Source\janderland_config.yml
02:16:47.588 DEBUG Plugin loaded: hexo-renderer-marked
02:16:47.588 DEBUG Plugin loaded: hexo-generator-index
02:16:47.588 DEBUG Plugin loaded: hexo-generator-archive
02:16:47.588 DEBUG Plugin loaded: hexo-renderer-ejs
02:16:47.603 DEBUG Plugin loaded: hexo-generator-category
02:16:47.603 DEBUG Plugin loaded: hexo-generator-tag
02:16:47.635 DEBUG Plugin loaded: hexo-server
02:16:47.650 DEBUG Loading database.
02:16:47.650 INFO Start processing
02:16:48.430 DEBUG Theme config loaded.
02:16:48.430 DEBUG Processed: _config.yml
02:16:48.430 DEBUG Processed: source/css/foundation-icons.css
02:16:48.430 DEBUG Processed: source/css/foundation-icons.eot
02:16:48.446 DEBUG Processed: source/css/foundation-icons.ttf
02:16:48.446 DEBUG Processed: source/css/foundation-icons.woff
02:16:48.446 DEBUG Processed: source/css/jander.css
02:16:48.446 DEBUG Processed: source/js/index.js
02:16:48.446 DEBUG Processed: source/js/app.js
02:16:48.539 DEBUG Processed: layout/index.ejs
02:16:48.539 DEBUG Processed: layout/layout.ejs
02:16:48.555 DEBUG Processed: source/css/foundation.css
02:16:48.851 DEBUG Processed: layout/post.ejs
02:16:48.851 DEBUG Processed: source/css/foundation-icons.svg
02:16:48.961 DEBUG Processed: layout/_partials/css.ejs
02:16:48.961 DEBUG Processed: layout/_partials/js.ejs
02:16:48.961 DEBUG Processed: layout/_partials/list_posts.ejs
02:16:48.961 DEBUG Processed: _posts/Test.md
02:16:48.961 DEBUG Processed: _posts/This-is-a-dummy-post.md
02:16:48.961 DEBUG Processed: _posts/Heyo.md
02:16:48.961 DEBUG Processed: _posts/What-up-punks.md
fs.js:584
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
^

Error: EMFILE: too many open files, open 'C:\Users\andjon\Source\janderland\node_modules\readdirp\stream-api.js'
at Error (native)
at Object.fs.openSync (fs.js:584:18)
at Object.fs.readFileSync (fs.js:431:33)
at Object.Module._extensions..js (module.js:421:20)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at readdir (C:\Users\andjon\Source\janderland\node_modules\readdirp\readdirp.js:52:25)
at FSWatcher. (C:\Users\andjon\Source\janderland\node_modules\chokidar\lib\nodefs-handler.js:355:5)
at FSWatcher.NodeFsHandler._handleDir (C:\Users\andjon\Source\janderland\node_modules\chokidar\lib\nodefs-handler.js:406:18)
at FSWatcher. (C:\Users\andjon\Source\janderland\node_modules\chokidar\lib\nodefs-handler.js:455:19)
at FSWatcher. (C:\Users\andjon\Source\janderland\node_modules\chokidar\lib\nodefs-handler.js:460:16)
at FSReqWrap.oncomplete (fs.js:82:15)

I tested the exact same hexo site on my Macbook and an EMFILE error is never thrown.

Notice that the EMFILE error actually occur's during a require() call by the readdirp module. One possible solution could be to 'gracefulify' the fs module during the hexo-fs module's initialization...

var fs = require('graceful-fs'); var nodeFs = require('fs'); fs.gracefulify(nodeFs);

... though I haven't tested the effects this would have on performance.

Dev server cannot serve video to iOS devices (server does not reply to range requests properly)

Expected behavior

hexo server should run a server that can reply to range requests appropriately. When viewing a video from a post we would expect that an iPhone user should be able to view it. Apple Safari strictly uses range requests to fetch video content so we expect Hexo's server to support this and serve the video just fine.

Actual behavior

Viewing under wireshark we can see clearly that the server is not replying to range requests the way that it should. Safari browser thus does not bother to cache any of the video and fails to play it at all. Works fine in Chrome on desktop.

How to reproduce?

  • create an appopriately encoded video

Apple is also very finicky about this too, I use the following technique to create an iOS-compatible mp4 file:

#!/bin/bash
# Usage: this_script.sh input_file output_file
ffmpeg -an -i $1 -c:v libx264 -profile:v baseline -level 3.0 -c:a aac -movflags +faststart \
-filter_complex "[0:v]scale=ih*16/9:-1,boxblur=luma_radius=min(h\\,w)/20:luma_power=1:chroma_radius=min(cw\\,ch)/20:chroma_power=1[bg];[bg][0:v]overlay=(W-w)/2:(H-h)/2,crop=h=iw*9/16" \
 $2
  • create a post with the video embedded:
<video controls>
  <source src="{% asset_path test.mp4 %}" type="video/mp4">
  Sorry, your browser doesn't support embedded videos.
</video>
  • run the server with hexo server
  • try to view the post and witness it not working
  • now generate the static files with hexo generate and run npx http-server -p 4000 (it will serve public folder automatically)
  • view the video and see that it will play fine (if your encoding is okay, per ffmpeg commands above)
  • view it with wireshark if you want and see the difference between the way the two servers handle the range request coming from the browser.

Is the problem still there under "Safe mode"?

N/A

Environment & Settings

Node.js & npm version(node -v && npm -v)

v14.17.0

Hexo and Plugin version(npm ls --depth 0)

Your package.json package.json

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "hexo server",
    "hexo": "hexo"
  },
  "hexo": {
    "version": "5.4.0"
  },
  "dependencies": {
    "hexo": "^5.4.0",
    "hexo-cli": "^4.3.0",
    "hexo-deployer-git": "^3.0.0",
    "hexo-generator-archive": "^1.0.0",
    "hexo-generator-category": "^1.0.0",
    "hexo-generator-cname3": "^1.0.1",
    "hexo-generator-feed": "^3.0.0",
    "hexo-generator-index": "^2.0.0",
    "hexo-generator-tag": "^1.0.0",
    "hexo-renderer-ejs": "^1.0.0",
    "hexo-renderer-marked": "^4.1.0",
    "hexo-renderer-stylus": "^2.0.1",
    "hexo-server": "^2.0.0"
  }
}

Others

Apple's finicky nature both in encoding and in serving video files for Safari are defined here:
https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/CreatingVideoforSafarioniPhone/CreatingVideoforSafarioniPhone.html#//apple_ref/doc/uid/TP40006514-SW4

hexo 3.1 : How to unwatch file change ?

below this command, show rendered articles in public dictionary.

$ hexo server -s

I found that if change markdown file, and hexo server show old data in expect. However, why nodejs run in background and spend a lot of CPU and Memory.

monitor Evented I/O for V8 javascript, right ?

Updating theme throws EISDIR

I receive EISDIR error in this scenario:

  1. hexo server
  2. Update a file in themes folder.
  3. Receive this:
INFO  Hexo is running at http://0.0.0.0:4000/. Press Ctrl+C to stop.
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: EISDIR, read
    at Error (native)

Servedsite in language other than what was set when not using -s flag

I'm doing initial configuration on my blog (in theory, you could clone and try this yourself) and after going through steps listed here https://gist.github.com/btfak/18938572f5df000ebe06fbd1872e4e39 I ran the command : hexo server

And I noticed the site render in (first) Russian and then when I switched tabs French. Very weird. I eventually tried hexo server -s and the pages rendered as expected.

My conclusion is for whatever reason when it was serving without the -s flag it rendered in a (basically) a random language. I did try to set the _config.yml language setting to en but that didn't change the result.

I restarted the server several times.

Hexo Server does not work in Cloud 9

Just logging this issue for those who run into the problem in the future.

To run hexo server with Cloud9 workspace, you need to use port 8080 rather than the default port.

hexo server --port 8080

UPDATE:

Cloud9 is now merged with AWS Cloud9, and it's not quite as easy to get hexo server running. Follow instructions from this page. Usually it has to do with a blocked port (i.e. port 8080 is not an open inbound)

TypeError: The header content contains invalid characters

如果链接里包含urlencode 而且不以/结尾 会报错

比如 curl "http://localhost:4000/categories/web%E5%89%8D%E7%AB%AF" 会报下面这个错误

TypeError: The header content contains invalid characters
    at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:358:11)
    at /home/xjp/www/node_modules/hexo-server/lib/middlewares/route.js:27:11
    at call (/home/xjp/www/node_modules/connect/index.js:239:7)
    at next (/home/xjp/www/node_modules/connect/index.js:183:5)
    at /home/xjp/www/node_modules/hexo-server/lib/middlewares/header.js:9:5
    at call (/home/xjp/www/node_modules/connect/index.js:239:7)
    at next (/home/xjp/www/node_modules/connect/index.js:183:5)
    at call (/home/xjp/www/node_modules/connect/index.js:248:3)
    at next (/home/xjp/www/node_modules/connect/index.js:183:5)
    at next (/home/xjp/www/node_modules/connect/index.js:161:14)
    at next (/home/xjp/www/node_modules/connect/index.js:161:14)
    at next (/home/xjp/www/node_modules/connect/index.js:161:14)
    at next (/home/xjp/www/node_modules/connect/index.js:161:14)
    at next (/home/xjp/www/node_modules/connect/index.js:161:14)
    at next (/home/xjp/www/node_modules/connect/index.js:161:14)
    at Function.handle (/home/xjp/www/node_modules/connect/index.js:186:3)

但是 curl "http://localhost:4000/categories/web%E5%89%8D%E7%AB%AF/" 就不会有问题

这个算是bug吗

bash$ hexo -v

hexo: 3.2.2
hexo-cli: 1.0.2
os: Darwin 16.3.0 darwin x64
http_parser: 2.7.0
node: 6.9.2
v8: 5.1.281.88
uv: 1.9.1
zlib: 1.2.8
ares: 1.10.1-DEV
icu: 57.1
modules: 48
openssl: 1.0.2j

Server should check whether header has already been set to prevent overwriting

This line:

res.setHeader('Content-Type', extname ? mime.lookup(extname) : 'application/octet-stream');

interferes with my own middleware, which sets Content-Type for files that are not recognised by mime.lookup, but then the header gets overwritten by the above line.

The router middleware should check if the header has already been set before trying to set its value.

Debugging in VScode: Websocket error using `127.0.0.1` with node inspector

Problem

hexo server does not recognize 127.0.0.1 as the same as "localhost."

Environment

  • MacOS 13.2.1

  • node: v19.6.1

  • Hexo:

    • hexo: 6.3.0
    • hexo-cli: 4.2.0
    • os: Darwin 22.3.0 darwin x64
    • node: 19.6.1
    • v8: 10.8.168.25-node.11
    • uv: 1.44.2
    • zlib: 1.2.11
    • brotli: 1.0.9
    • ares: 1.19.0
    • modules: 111
    • nghttp2: 1.52.0
    • napi: 8
    • llhttp: 8.1.0
    • uvwasi: 0.0.15
    • acorn: 8.8.2
    • simdutf: 3.1.0
    • undici: 5.19.1
    • openssl: 1.1.1t
    • cldr: 42.0
    • icu: 72.1
    • tz: 2022e
    • unicode: 15.0

VScode launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "pwa-node",
            "name": "Hexo Theme inspector",
            "request": "attach",
            "program": "${workspaceFolder}/node_modules/hexo-cli/bin/hexo",
            "args": [
                "server",
                "-p 4001",
                "--debug"
            ],
            "runtimeExecutable": "node",
            "runtimeArgs": [
                "--inspect-brk=4001"
            ],
            "processId": "${command:PickProcess}",
            "protocol": "inspector",
            "address": "localhost",
            "port": 4001,
            "restart": true,
            "sourceMaps": true,
            "sourceMapPathOverrides": {
                "webpack:///./src/views/*": "${workspaceFolder}/views/*",
                "webpack:///./src/*": "${workspaceFolder}/src/*",
                "webpack:///./../src/*": "${workspaceFolder}/src/*"
            },
            "resolveSourceMapLocations": [
                "${workspaceFolder}/**",
                "!**/node_modules/**"
            ],
            "outFiles": [
                "${workspaceFolder}/**/*.js",
                "${workspaceFolder}/**/*.ejs",
                "${workspaceFolder}/public/**",
                "${workspaceFolder}/themes/**/*.ejs",
                "${workspaceFolder}/themes/**/*.css",
                "${workspaceFolder}/themes/**/*.scss",
                "${workspaceFolder}/themes/**/*.sass",
                "${workspaceFolder}/themes/**/*.less",
                "${workspaceFolder}/themes/**/*.styl",
                "${workspaceFolder}/themes/**/*.png",
                "${workspaceFolder}/themes/**/*.jpg",
                "${workspaceFolder}/themes/**/*.jpeg",
                "${workspaceFolder}/themes/**/*.gif",
                "${workspaceFolder}/themes/**/*.svg",
                "${workspaceFolder}/themes/**/*.woff",
                "${workspaceFolder}/themes/**/*.woff2",
                "${workspaceFolder}/themes/**/*.eot",
                "${workspaceFolder}/themes/**/*.ttf"
            ],
            "localRoot": "${workspaceFolder}",
            "remoteRoot": "${workspaceFolder}",
            "cwd": "${workspaceFolder}",
            "console": "internalConsole",
            "skipFiles": ["<node_internals>/**"]
        }
    ]
}

Debugging with Node

Running the following command in VScode terminal does not properly bind to the default IP address of 127.0.0.1. The server errors with "WebSockets request was expected."

$(which hexo) clean && node --inspect-brk=4001 $(which hexo) server -i localhost -p 4001 --debug

image

image
image

Without Node Inspector

I observe if I run Hexo without node inspect, then Hexo will properly bind to both 127.0.0.1 and localhost.

$(which hexo) clean && $(which hexo) server --debug

Expected behavior

Server should accept both "localhost" and "127.0.0.1" on MacOS. Even with Node Inspector, it should respond correctly to IP and "localhost" as the domain.

In windows, i'm unable to use the same port after server has started

Problem

In windows, i'm unable to use the same port after server has started. It says it's being in use:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\cygwin64\home\chris\workspace\hexo-zf>hexo server --port=4001
hexo server --port=4001
FATAL Port 4001 has been used. Try other port instead.
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Error: listen EADDRINUSE
    at errnoException (net.js:901:11)
    at Server._listen2 (net.js:1039:14)
    at listen (net.js:1061:10)
    at net.js:1135:9
    at dns.js:72:18
    at process._tickCallback (node.js:415:13)

I don't have any other instances of the server running. I double checked as well.

Steps to reproduce

  1. Start the server hexo server
  2. Stop the server
  3. Try to start it again with the same port

Configuration

package.json:

{
"name": "hexo-site",
"version": "0.0.0",
"private": true,
"hexo": {
"version": "3.0.1"
},
"dependencies": {
"hexo": "^3.0.0",
"hexo-generator-archive": "^0.1.0",
"hexo-generator-category": "^0.1.0",
"hexo-generator-index": "^0.1.0",
"hexo-generator-tag": "^0.1.0",
"hexo-renderer-ejs": "^0.1.0",
"hexo-renderer-stylus": "^0.2.0",
"hexo-renderer-marked": "^0.2.4",
"hexo-server": "^0.1.2",
"hexo-browsersync": "~0.1.1"
}
}

_config.yml

# Hexo Configuration
## Docs: http://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: Hexo
subtitle:
description:
author: John Doe
language:
timezone:

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://yoursite.com
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:

# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
  enable: true
  line_number: true
  tab_replace:

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# LiveReload
# https://www.npmjs.com/package/hexo-livereload
livereload:
  port: 35729

# Extensions
## Plugins: http://hexo.io/plugins/
## Themes: http://hexo.io/themes/
theme: landscape

# Deployment
## Docs: http://hexo.io/docs/deployment.html
deploy:
  type:

Debugging in VScode: "port already in use" error

Problem

hexo server fails to bind to 127.0.0.1 while using node inspector. If you explicitly define the IP and port the same as that configured for Node Inspector, it will fail to start.

$(which hexo) clean && node --inspect-brk=4001 $(which hexo) server -i localhost -p 4001 --debug

Screenshot 2023-02-22 at 12 23 27

However, if you don't define the IP and leave it to defaults, everything starts, but the browser doesn't reach the server over 127.0.0.1...

$(which hexo) clean && node --inspect-brk=4001 $(which hexo) server -p 4001

Screenshot

Related issue

Environment

  • MacOS 13.2.1

  • node: v19.6.1

  • Hexo:

    • hexo: 6.3.0
    • hexo-cli: 4.2.0
    • os: Darwin 22.3.0 darwin x64
    • node: 19.6.1
    • v8: 10.8.168.25-node.11
    • uv: 1.44.2
    • zlib: 1.2.11
    • brotli: 1.0.9
    • ares: 1.19.0
    • modules: 111
    • nghttp2: 1.52.0
    • napi: 8
    • llhttp: 8.1.0
    • uvwasi: 0.0.15
    • acorn: 8.8.2
    • simdutf: 3.1.0
    • undici: 5.19.1
    • openssl: 1.1.1t
    • cldr: 42.0
    • icu: 72.1
    • tz: 2022e
    • unicode: 15.0

Expected behavior

Server should work Node inspector. How else does one troubleshoot issues if it won't bind on the same domain (IP) and port? IP alias?

Add support utf8

Hi this is a great part of HEXO, but I wish you would add support for utf8 in the response headers. Having non-english chars like: "æøå" (danish letters) does not work when running hexo server. utf8 needs to be set in the nodejs server :-)

--debug flag is not working with node-inspector

Hi guys, just try to create a new hexo-server 3rd party component, when I try to debug the hexo-server with node-inspector, seems it is not working. Is there any other way to debug the hexo-server ?

Serve on both IPv4 and IPv6 interfaces by default

Currently, hexo serve only listens to IPv4 intefaces. To get the IPv6 ::1, you have to pass it explicitly with the ip option (but then the server is not bound to the IPv4 interfaces).

Would it be possible to make hexo serve listen on all interfaces by default?

[BUG] `hexo server` hanging forever when repo contains any invalid symbolic link

Environment Info

Node version(node -v): v6.9.1 (in nvm)
OS: Chakra Linux

Your site _config.yml (Optional):

Your theme _config.yml (Optional):

Hexo and Plugin version(npm ls --depth 0):

[email protected] /home/onohiroko/source-blog
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

For question

After hexo server --debug, it stopped at a fixed point, then hang and server still not startup:

./node_modules/hexo-cli/bin/hexo server --debug                                                                                                                                                                (01-04 10:11)
02:11:19.915 DEBUG Hexo version: 3.2.2                                                 
02:11:19.917 DEBUG Working directory: ~/source-blog/                                   
02:11:19.988 DEBUG Config loaded: ~/source-blog/_config.yml                          
02:11:20.101 DEBUG Script loaded: scripts/livedoor-opml2md.js                          
02:11:20.101 DEBUG Script loaded: scripts/toc.js                                      
02:11:20.102 DEBUG Script loaded: themes/taiga/scripts/fancybox.js                        
02:11:20.103 DEBUG Plugin loaded: hexo-cli                                                  
02:11:20.105 DEBUG Plugin loaded: hexo-generator-archive                      
02:11:20.106 DEBUG Plugin loaded: hexo-generator-category                          
02:11:20.144 DEBUG Plugin loaded: hexo-deployer-git                                 
02:11:20.146 DEBUG Plugin loaded: hexo-generator-feed                             
02:11:20.146 DEBUG Plugin loaded: hexo-generator-index                                 
02:11:20.147 DEBUG Plugin loaded: hexo-generator-sitemap                              
02:11:20.149 DEBUG Plugin loaded: hexo-renderer-ejs                                  
02:11:20.230 DEBUG Plugin loaded: hexo-renderer-stylus                                                                                                                                                                                                              
02:11:20.231 DEBUG Plugin loaded: hexo-generator-tag                                                                                                                                                                                                                
02:11:20.235 DEBUG Plugin loaded: hexo-renderer-marked                  
02:11:20.273 DEBUG Plugin loaded: hexo-server                                                                                                                                                                                                                       
02:11:20.280 DEBUG Loading database.                                
02:11:20.451 INFO  Start processing                             
02:11:20.654 DEBUG Processed: _drafts/2017-malaysia-singapore.md      
......... (articles)
02:11:20.721 DEBUG Theme config loaded.                                              
02:11:20.722 DEBUG Processed: _config.yml                                                                                                                                                                                                                           
02:11:20.722 DEBUG Processed: image/banner/03.jpg                                                                                                                                                                                                                   
02:11:20.722 DEBUG Processed: image/banner/02.jpg                       
02:11:20.723 DEBUG Processed: lists/dist/ui-bootstrap-tpls-2.5.0.min.js                                                                                                                                                                                             
02:11:20.723 DEBUG Processed: transcription/Skyrim_Main_Theme.pdf   
......... (files)
02:11:20.854 DEBUG Processed: image/2014/IMG_6379.jpg                                      
02:11:20.854 DEBUG Processed: image/2014/IMG_6382.jpg                                   
02:11:20.860 DEBUG Processed: image/2014/IMG_6386.jpg                                 
02:11:20.897 DEBUG Processed: file/2015/1947_Overture_cover.pdf                      
^C02:14:02.583 INFO  See you again                                                      
02:14:02.633 DEBUG Database saved   

It freezed at 02:11:20.897, so I press ^C to interrupt.

Some possibly usable clues:

  1. Firewall is not running.
  2. I didn't encounter this problem on macOS.
  3. 4000 port is not be occupied by others.
  4. hexo is not installed system globally.

URI malformed and no reason.

MacBook-Pro:xxx lionvii$ hexo s
INFO Hexo is running at http://0.0.0.0:4000/. Press Ctrl+C to stop.
URIError: URI malformed
at decodeURIComponent (native)
at /Users/lionvii/xxx/node_modules/hexo-server/lib/middlewares/route.js:18:50
at call (/Users/lionvii/xxx/node_modules/hexo-server/node_modules/connect/lib/proto.js:210:7)
at next (/Users/lionvii/xxx/node_modules/hexo-server/node_modules/connect/lib/proto.js:154:5)
at compression (/Users/lionvii/xxx/node_modules/hexo-server/node_modules/compression/index.js:212:5)
at call (/Users/lionvii/xxx/node_modules/hexo-server/node_modules/connect/lib/proto.js:210:7)
at next (/Users/lionvii/xxx/node_modules/hexo-server/node_modules/connect/lib/proto.js:154:5)
at /Users/lionvii/xxx/node_modules/hexo-server/lib/middlewares/header.js:6:5
at call (/Users/lionvii/xxx/node_modules/hexo-server/node_modules/connect/lib/proto.js:210:7)
at next (/Users/lionvii/xxx/node_modules/hexo-server/node_modules/connect/lib/proto.js:154:5)
at Function.app.handle (/Users/lionvii/xxx/node_modules/hexo-server/node_modules/connect/lib/proto.js:157:3)
at Server.app (/Users/lionvii/xxx/node_modules/hexo-server/node_modules/connect/lib/connect.js:28:37)
at Server.emit (events.js:110:17)
at HTTPParser.parserOnIncoming as onIncoming
at HTTPParser.parserOnHeadersComplete (_http_common.js:111:23)
at Socket.socketOnData (_http_server.js:343:22)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:529:20)

run hexo server throw TypeError

I migrating 2 -> 3
https://github.com/hexojs/hexo/wiki/Migrating-from-2.x-to-3.0

when i run

hexo server

throw

E:\ProjectGitHub\Blogs\youxiachaiblog>hexo server
[error] TypeError: Cannot read property 'server' of undefined
TypeError: Cannot read property 'server' of undefined
    at server (E:\ProjectGitHub\Blogs\youxiachaiblog\node_modules\hexo-server\lib\server.js:9:39)
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\hexo\lib\core\index.js:227:7
    at b (domain.js:183:18)
    at Domain.run (domain.js:123:23)
    at Hexo.call (C:\Users\Administrator\AppData\Roaming\npm\node_modules\hexo\lib\core\index.js:226
:7)
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\hexo\lib\init.js:64:10
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\hexo\node_modules\async\lib\async.js:
157:25
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\hexo\node_modules\async\lib\async.js:
254:17
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\hexo\node_modules\async\lib\async.js:
157:25
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\hexo\node_modules\async\lib\async.js:
251:21
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\hexo\node_modules\async\lib\async.js:
615:34
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\hexo\lib\loaders\scripts.js:10:24
    at Object.cb [as oncomplete] (fs.js:168:19)

Caching possible?

Every page view re-generate the .css file from a custom modified UIKit-scss files. This takes on each page view ~750ms.

Is it possible to pass options to hexo, so that hexo did not render the css file each time, only if scss files are modified?

When writing docs and view small changes, it is annoying to wait each time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.