perak / kitchen-examples

Meteor Kitchen examples
164 stars 115 forks source link

IDE example: new routes don't seem accessible #29

Closed whatsdis closed 8 years ago

whatsdis commented 8 years ago

so I created a route along with all the other routes there by default, created a controller, but when I navigate to it, I get 404.

perak commented 8 years ago
  1. Where did you made new route? In your input.json file, or directly in generated application?
  2. How you made route (gimme example).
whatsdis commented 8 years ago
  1. client\views\router.js
    this.route("apis", {path: "/apis/:apiUrl", controller: "ApiController"});
Router.map(function () {

    this.route("home_public", {path: "/", controller: "HomePublicController"});
    this.route("login", {path: "/login", controller: "LoginController"});
    this.route("register", {path: "/register", controller: "RegisterController"});
    this.route("forgot_password", {path: "/forgot_password", controller: "ForgotPasswordController"});
    this.route("reset_password", {path: "/reset_password/:resetPasswordToken", controller: "ResetPasswordController"});
    this.route("projects", {path: "/projects", controller: "ProjectsController"});
    this.route("projects.main", {path: "/projects/main/:projectId/:fileId", controller: "ProjectsMainController"});
    this.route("projects.main.editor", {path: "/projects/main/:projectId/:fileId/editor", controller: "ProjectsMainEditorController"});
    this.route("projects.insert", {path: "/projects/insert", controller: "ProjectsInsertController"});
    this.route("projects.edit", {path: "/projects/edit/:projectId", controller: "ProjectsEditController"});
    this.route("admin", {path: "/admin", controller: "AdminController"});
    this.route("admin.users", {path: "/admin/users", controller: "AdminUsersController"});
    this.route("admin.users.details", {path: "/admin/users/details/:userId", controller: "AdminUsersDetailsController"});
    this.route("admin.users.insert", {path: "/admin/users/insert", controller: "AdminUsersInsertController"});
    this.route("admin.users.edit", {path: "/admin/users/edit/:userId", controller: "AdminUsersEditController"});
    this.route("user_settings", {path: "/user_settings", controller: "UserSettingsController"});
    this.route("user_settings.profile", {path: "/user_settings/profile", controller: "UserSettingsProfileController"});
    this.route("user_settings.change_pass", {path: "/user_settings/change_pass", controller: "UserSettingsChangePassController"});
    this.route("logout", {path: "/logout", controller: "LogoutController"});
    this.route("apis", {path: "/apis/:apiUrl", controller: "ApiController"});
});

and I've got all the necessary files in the api/ folder, api.html, apiController.js, api.js

  1. localhost:3000/apis

returns 404.

perak commented 8 years ago

@whatsdis you need apiUrl in your URL, so localhost:3000/apis will not work, but localhost:3000/apis/anything will work.

If you want apiUrl to be optional, then you need to define it with question mark:

this.route("apis", {path: "/apis/:apiUrl?", controller: "ApiController"});

in that case, both: localhost:3000/apis and localhost:3000/apis/anything will work.

perak commented 8 years ago

BTW, just guessing - if your apis route should expose server-side only API (API is usually without GUI, that's why I believe you need that), then you can define it as server-side route. In meteor kitchen you can do it by setting application.server_side_routes, or directly in generated app like this:

Somewhere under /server/ directory:

Router.map(function () {
    this.route("apis", {path: "/apis/:apiUrl?", controller: "ApisController", where: "server"});
});

(see meteor-kitchen source code: https://github.com/perak/kitchen-site/blob/master/meteor-kitchen.json#L964 there are two server side routes).

whatsdis commented 8 years ago

@perak no actually wasn't making it a server side thing, apis/ just a page that displays list.

when i navigate to /apis/test, it just shows a blank page, inspecting the elements doesn't seem to show the expected html.

<template name="Api">
    <div class="page-container container" id="content">
        <div class="row" id="title_row">
            <div class="col-md-12">
                test
            </div>
        </div>
    </div>
</template>
perak commented 8 years ago

Your template should be named "Apis" not "Api" (unless you specify different in route definition or in controller. And do you have controller? Also, do you have any errors in console when you navigate to that url?

whatsdis commented 8 years ago

will give that a try

whatsdis commented 8 years ago

yup that did it! thanks again @perak!

perak commented 8 years ago

:+1: