node.js - 在 nodejs 中使用不同的主机制作 API
问题描述
我是 nodejs 的新手,目前localhost
用于运行模拟 API。
index.js -
const express = require("express");
const api = require("./routes/api");
const app = express();
// Routes
app.use("/api", api); // route api
路线/api/index.js -
const router = express.Router();
router.get("/path-to-certain-resource", async (req, res) => {
});
//...
router.post("/path-to-another-resource", async(req,res) => {
});
我需要使用预定义的 url 创建一个新的 API - 例如https://example.com/api/v1/users
我怎样才能做到这一点?
解决方案
推荐阅读
- python - SQLAlchemy 引擎和会话对象的类型提示
- web-services - Web 服务因 org.apache.axis2.AxisFault 失败:系统无法从 [my URL] URL 推断传输信息
- c# - 有没有办法使用 lambda 表达式编写这个 LINQ 查询?
- python - 提取具有特定方言的推文的最有效方法是什么?
- python - Python:回车在第 10000 次后停止工作
- ssl - 我的微服务是否也需要 TLS,或者 Ingress TLS 终止是否足够?
- azure-devops - Linux 托管代理和 Azure 工件(符号发布)
- r - 如何重新启动 R 并从上一行(在 Windows 上)继续执行基准测试脚本?
- ruby-on-rails - 资源选择器不会显示
- python - 从多天的日期时间时间戳列表中,如何找到每天的最后一个时间戳?