Express jsを使用してテストapiアプリケーションを作成しようとしました。私は、インターネット上で利用可能な多くの方法を採用して、ノードjs APIアプリケーションを展開して実行します。しかし、私の場合は何も働いていません。私を助けてください。エクスプレスjs apiエンドポイントが晴れのあるWebアプリケーションでは機能しない
他の賢明な私は紺やノードjsを残す必要があります。
私は下のすべてのファイルを添付しています: 1.index.js
var express = require('express');
var app = express();
router.get('/things', function(req, res) {
res.json('GET route on things.');
});
router.post('/things', function(req, res) {
res.json('POST route on things.');
});
app.get('/hello', function(req, res) {
res.json("Hello World!");
});
app.post('/hello', function(req, res) {
res.json("You just called the post method at '/hello'!\n");
});
const port = process.env.PORT || 1337;
app.listen(port);
{
"name": "testabc",
"version": "1.0.0",
"description": "test api",
"main": "index.js",
"engines": {
"node": "^7.10.0"
},
"scripts": {
"test": "test",
"start": "node index.js",
"prestart": "npm install"
},
"repository": {
"type": "git",
"url": "none"
},
"keywords": [
"test"
],
"author": "rakesh",
"license": "ISC",
"dependencies": {
"express": "^4.16.2"
}
}
3。 package.json
{
"name": "testabc",
"version": "1.0.0",
"description": "test api",
"main": "index.js",
"engines": {
"node": "^7.10.0"
},
"scripts": {
"test": "test",
"start": "node index.js",
"prestart": "npm install"
},
"repository": {
"type": "git",
"url": "none"
},
"keywords": [
"test"
],
"author": "rakesh",
"license": "ISC",
"dependencies": {
"express": "^4.16.2"
}
}
4.web.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="index.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="myapp">
<match url="/*" />
<action type="Rewrite" url="index.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
すべてのコードを提供するのではなく、エラーを確認することをお勧めします。 – Deep
「探しているリソースが削除された、名前が変更された、一時的に使用できない」などのエラーが発生することがあります。 – kmrrakesh
"hello"という経路にしか反応しませんが、 "things"という経路を消費しようとすると、上記のエラーが発生します。 – kmrrakesh