我正在node.js端口8080上运行webrtc,我正在尝试重写node.js上的url
我安装了connect-url-rewrite和connect-modrewrite这两个模块
你能给我一些例子吗?在哪里可以在server.js或html页面上添加脚本?
敬请指教
发布于 2014-01-24 01:12:19
您不需要同时使用connect-url-rewrite和connect-modrewrite。选择其中的一个,然后跟着它走。
本质上,您创建一个Connect应用程序,并在其上调用use,传入带有一组规则的重写函数。There's a good example the Github page for connect-modrewrite.我在这里重新发布了它,并做了一些简化:
var app = connect()
app.use(modRewrite([
'^/test$ /index.html',
'^/test/\\d*$ /index.html [L]',
'^/test/\\d*/\\d*$ /flag.html [L]'
]))
app.use(connect.static(PATH_TO_STATIC_FILES_DIR))
app.listen(3000)如果您不知道modRewrite调用中的字符串是什么意思,那么您必须阅读一些重写规则。本质上,该模式是:<regular expression for url fragment> <target> <optional flags>
希望这能有所帮助!
https://stackoverflow.com/questions/21242817
复制相似问题