gpt4 book ai didi

node.js - Express JS api 端点在 azure web 应用程序上不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 01:56:47 25 4
gpt4 key购买 nike

我刚刚尝试使用 Express js 创建一个测试 api 应用程序。我采用了互联网上的许多可用方法来部署和运行 Node js api 应用程序。但对我来说没有任何作用。请帮助我。

否则我将不得不离开azure或node 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);
2.package-lock.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"
}
}

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>

最佳答案

var express = require('express');
var app = express();
var router = express.Router();

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);

关于node.js - Express JS api 端点在 azure web 应用程序上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47653163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com