Re: [Cppcms-users] 404 Not Found even with valid URLs
Brought to you by:
artyom-beilis
From: Nazım C. B. <naz...@ne...> - 2017-02-18 12:18:57
|
Hello, There is inconsistency in your dispatcher and mapper code. As far as I understand, you would like to use your URLs like "/students/list", "/students/add", etc. For this to work, you have two different approaches; * You need to mount your application with "/students" prefix. If you choose this way, then you don't need to set mapper root, and can dispatch and map as "/add", "/list", "/show", etc. * You need to maintain prefix manually, and 1) set mapper root to that prefix, 2) prefix all of your dispatch rules appropriately. In your code, you are mounting your application to "/", and setting mapper root to "/students" but your dispatch codes doesn't have "/students" prefix. This is your code: } dispatcher().assign("/add", &students::add, this); mapper().assign("add", "/add"); std::cout << "Added add script" << std::endl; dispatcher().assign("", &students::list, this); mapper().assign(""); dispatcher().assign("/list", &students::list, this); mapper().assign("list", "/list"); dispatcher().assign("/show/(\\d)+", &students::show, this, 1); mapper().assign("show", "/show/{1}"); dispatcher().assign("/update/(\\d)+", &students::update, this, 1); mapper().assign("update", "/update/{1}"); mapper().root("/students"); } This is how it should look: } dispatcher().assign("/students/add", &students::add, this); mapper().assign("add", "/add"); std::cout << "Added add script" << std::endl; dispatcher().assign("/students", &students::list, this); mapper().assign("/students"); dispatcher().assign("/students/list", &students::list, this); mapper().assign("list", "/list"); dispatcher().assign("/students/show/(\\d)+", &students::show, this, 1); mapper().assign("show", "/show/{1}"); dispatcher().assign("/students/update/(\\d)+", &students::update, this, 1); mapper().assign("update", "/update/{1}"); mapper().root("/students"); } After making changes, I am able to visit addresses and get output from the console. Regards, Nazim Can. On 18/02/17 14:52, abi...@ic... wrote: > Here’s the project. The dispatcher and mapper code is in the root > directory in the students.cpp file. > http://github.com/abbygriffiths/cppcms-student_record.git > > /Abirbhav Goswami/ > > On Feb 18, 2017, 5:03 PM +0530, Nazım Can Bedir > <naz...@ne...>, wrote: >> >> Can you share the code which one is believed to be correct? >> >> >> On 18/02/17 14:07, abi...@ic... wrote: >>> I made a small website and it’s giving me a 404 – Not Found error, >>> but I’m confident that the code isn’t wrong. Can someone point me in >>> the right direction? >>> >>> /Abirbhav Goswami/ >>> >>> >>> ------------------------------------------------------------------------------ >>> Check out the vibrant tech community on one of the world's most >>> engaging tech sites, SlashDot.org!http://sdm.link/slashdot >>> >>> >>> _______________________________________________ >>> Cppcms-users mailing list >>> Cpp...@li... >>> https://lists.sourceforge.net/lists/listinfo/cppcms-users >> >> ------------------------------------------------------------------------------ >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, SlashDot.org! http://sdm.link/slashdot >> _______________________________________________ >> Cppcms-users mailing list >> Cpp...@li... >> https://lists.sourceforge.net/lists/listinfo/cppcms-users > > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, SlashDot.org! http://sdm.link/slashdot > > > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users |