New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server_middleware for 404 page #1030

szarouski opened this Issue Feb 4, 2015 · 2 comments


2 participants

szarouski commented Feb 4, 2015

Hi, I was trying to set 404 page handler using server_middleware, but it appears that plugins code from my theme folder will execute before hexo-server plugin will register its own 'server_middleware' plugins. 404 page middleware should be set at the end of connect middleware, but because it was registered first it will handle even valid pages and I don't see a way to handle 404 myself. Any ideas? Thank you.

In my theme plugins folder:

hexo.extend.filter.register('server_middleware', function _404middleware(app) {
    app.use(function handle404(req, res, next) {
        res.writeHead(302, {
            'Location': hexo.config.url + hexo.config.root

This comment has been minimized.


tommy351 commented Feb 4, 2015

You can try to add priority option to the filter. Bigger priority runs later. The default priority is 10.

hexo.extend.filter.register('server_middleware', function(app){
  // ...
}, 99)

This comment has been minimized.

szarouski commented Feb 4, 2015

Very nice, thank you

@szarouski szarouski closed this Feb 4, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment