Skip to content
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

Closed
webuniverseio opened this issue Feb 4, 2015 · 2 comments
Closed

server_middleware for 404 page #1030

webuniverseio opened this issue Feb 4, 2015 · 2 comments

Comments

@webuniverseio
Copy link

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
        });
        res.end();
    });
});
@tommy351
Copy link
Member

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)

@webuniverseio
Copy link
Author

Very nice, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants