update config to a middleware  and add test case