Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Azure应用程序服务添加'/';在URL中_Javascript_Node.js_Azure_Express - Fatal编程技术网

Javascript Azure应用程序服务添加'/';在URL中

Javascript Azure应用程序服务添加'/';在URL中,javascript,node.js,azure,express,Javascript,Node.js,Azure,Express,我正在开发部署在Azure应用程序服务上的node.js应用程序 应用程序在本地主机上按预期运行- http://localhost:55231/search?q=pink+弗洛伊德 但是当部署在Azure上时,URL的行为很奇怪- http://.azurewebsites.net/search/?q=pink+floyd查询字符串前的额外“/” 我的Express.js代码是- app.get('/search', function (req, res) { response = {

我正在开发部署在Azure应用程序服务上的node.js应用程序

应用程序在本地主机上按预期运行-

http://localhost:55231/search?q=pink+弗洛伊德

但是当部署在Azure上时,URL的行为很奇怪-

http://.azurewebsites.net/search/?q=pink+floyd
查询字符串前的额外“/”

我的Express.js代码是-

app.get('/search', function (req, res) {
  response = {
  search_text:req.query.q,
  };
//Few more code
网页服务查询-

<form action = "/search" method = "GET">
  <input type = "text" name = "q" placeholder=" Search your Favourite Music">
  <input type = "submit" value = "Search">
</form>

我无法使用Express在Azure应用程序服务上重现您的问题。然而,以下是我迄今为止所尝试的

我的文件夹结构:

我的app.js代码如下所示:

var express = require('express')
var app = express()

app.use(express.static('public'))

app.get('/', function (req, res) {
  res.send('Hello Azure!')
})

app.get('/search', function(req, res) {
  res.send(200, 'Test')
})

app.listen(process.env.PORT || 3000, function () {
  console.log('Example app listening on port 3000!')
})
My test.html代码:


试验
搜寻
web.config:



您可以共享您正在使用的web.config文件吗?我猜你错过了一件简单的事情。

我无法用Express在Azure应用程序服务上重现你的问题。然而,以下是我迄今为止所尝试的

我的文件夹结构:

我的app.js代码如下所示:

var express = require('express')
var app = express()

app.use(express.static('public'))

app.get('/', function (req, res) {
  res.send('Hello Azure!')
})

app.get('/search', function(req, res) {
  res.send(200, 'Test')
})

app.listen(process.env.PORT || 3000, function () {
  console.log('Example app listening on port 3000!')
})
My test.html代码:


试验
搜寻
web.config:


您可以共享您正在使用的web.config文件吗?我猜你错过了一件简单的事情

<?xml version="1.0" encoding="utf-8"?>
<!-- 
     This configuration file is required if iisnode is used to run node processes behind
     IIS or IIS Express.  For more information, visit:

     https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->

<configuration>
     <system.webServer>
          <!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
          <webSocket enabled="false" />
          <handlers>
               <!-- Indicates that the app.js file is a node.js site to be handled by the iisnode module -->
               <add name="iisnode" path="app.js" verb="*" modules="iisnode"/>
          </handlers>
          <rewrite>
               <rules>
                    <!-- Do not interfere with requests for node-inspector debugging -->
                    <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">                    
                        <match url="^app.js\/debug[\/]?" />
                    </rule>

                    <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
                    <rule name="StaticContent">
                         <action type="Rewrite" url="public{REQUEST_URI}"/>
                    </rule>

                    <!-- All other URLs are mapped to the node.js site entry point -->
                    <rule name="DynamicContent">
                         <conditions>
                              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
                         </conditions>
                         <action type="Rewrite" url="app.js"/>
                    </rule>
               </rules>
          </rewrite>

          <!-- bin directory has no special meaning in node.js and apps can be placed in it -->
          <security>
               <requestFiltering>
                    <hiddenSegments>
                         <remove segment="bin"/>
                    </hiddenSegments>
               </requestFiltering>
          </security>

          <!-- Make sure error responses are left untouched -->
          <httpErrors existingResponse="PassThrough" />

          <!--
               You can control how Node is hosted within IIS using the following options:
                 * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
                 * node_env: will be propagated to node as NODE_ENV environment variable
                 * debuggingEnabled - controls whether the built-in debugger is enabled

               To debug your node.js application:
                 * set the debuggingEnabled option to "true"
                 * enable web sockets from the portal at https://manage.windowsazure.com/#Workspaces/WebsiteExtension/Website/aaronexpress/configure
                 * browse to https://aaronexpress.azurewebsites.net/app.js/debug/

               See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
          -->
          <iisnode watchedFiles="web.config;*.js" debuggingEnabled="false" />
     </system.webServer>
</configuration>