榆树导航防止无法GET

时间:2016-10-14 21:25:44

标签: elm

我一直在玩Elm导航包,目前我正在使用Hop框架,我想知道是否有办法防止cannot GET /<url>消息没有前面的英镑符号网址(示例:#<url>)。

2 个答案:

答案 0 :(得分:2)

我觉得这可能是服务器配置问题。要让#-less网址正常工作,您需要将服务器配置为提供相同的.html,而不管请求网址是什么。提供后,您的Elm应用程序可以加载并从那里获取。

答案 1 :(得分:2)

为了补充Peter Szerzo的答案,我发现an issue at the Github page of browser-sync页面与我的问题大致相同。解决方案如下:

StringBuilder spawn_async_with_pipes_output;

private static bool process_line (IOChannel channel, IOCondition condition, string stream_name) {
    if (condition == IOCondition.HUP) {
        stdout.printf ("%s: The fd has been closed.\n", stream_name);
        return false;
    }

    try {
        string line;
        channel.read_line (out line, null, null);
        stdout.printf ("%s: %s", stream_name, line);
    } catch (IOChannelError e) {
        stdout.printf ("%s: IOChannelError: %s\n", stream_name, e.message);
        return false;
    } catch (ConvertError e) {
        stdout.printf ("%s: ConvertError: %s\n", stream_name, e.message);
        return false;
    }

    return true;
}

public int execute_sync_multiarg_command_pipes(string[] spawn_args) {
        debug("Starting to execute async command: "+string.joinv(" ", spawn_args));
        spawn_async_with_pipes_output.erase(0, -1); //clear the output buffer
        MainLoop loop = new MainLoop ();
        try {
            string[] spawn_env = Environ.get();
            Pid child_pid;

            int standard_input;
            int standard_output;
            int standard_error;

            Process.spawn_async_with_pipes ("/",
                spawn_args,
                spawn_env,
                SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD,
                null,
                out child_pid,
                out standard_input,
                out standard_output,
                out standard_error);

            // capture stdout:
            IOChannel output = new IOChannel.unix_new (standard_output);
            output.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => {
                return process_line (channel, condition, "stdout");
            });

            // capture stderr:
            IOChannel error = new IOChannel.unix_new (standard_error);
            error.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => {
                return process_line (channel, condition, "stderr");
            });

            ChildWatch.add (child_pid, (pid, status) => {
                // Triggered when the child indicated by child_pid exits
                Process.close_pid (pid);
                loop.quit ();
            });
            loop.run ();
        } catch(SpawnError e) {
            warning("Failure in executing async command ["+string.joinv(" ", spawn_args)+"] : "+e.message);
            spawn_async_with_pipes_output.append(e.message);
        }
        debug("Completed executing async command["+string.joinv(" ", spawn_args)+"]...");
        return 0;
    }

public static int main (string[] args) {
    spawn_async_with_pipes_output = new StringBuilder ();
    execute_sync_multiarg_command_pipes ({"pkexec", "ls", "-l", "-h"});
    return 0;
}

如果您要使用Apache或Nginx,当然需要使用不同的解决方案。这是特定于浏览器同步的。

<强>更新

我遇到了另一个问题,上面的解决方案不起作用,因为它会从不同的位置再次获取项目。例如:手动导航到const modRewrite = require("connect-modrewrite"); gulp.task("serve", () => { browserSync.init(null, { middleware: [ modRewrite([ "!\\.\\w+$ /index.html [L]" ]), ] } } 可以很好地工作,因为在更改到该位置时没有任何HTTP请求,但是当重新加载页面时,页面将从/blog/1获取文件,上面的解决方案没有处理。这就是我解决后一个问题的方法:

/blog