【发布时间】:2022-10-23 23:57:57
【问题描述】:
我遵循的步骤:
bun create hono test-api
cd test-api
bun dev
然后服务器显示此消息:
$ bun dev
[1.00ms] bun!! v0.1.6
Link: http://localhost:3000
当我修改任何文件时,服务器会检测到它然后重新加载应用程序但我不知道如何调用我的应用程序 REST API。
如果我执行:curl localhost:3000 响应是一个转译的 JS 代码:
import {
__require
} from "http://localhost:3000/bun:wrap";
import {
__HMRClient as Bun
} from "http://localhost:3000/bun:wrap";
Bun.activate(false);
import {
__HMRModule as HMR
} from "http://localhost:3000/bun:wrap";
import * as $9121e9 from "http://localhost:3000/node_modules/hono/dist/index.js";
var { Hono} = __require($9121e9);
var hmr = new HMR(2320229645, "src/index.ts"), exports = hmr.exports;
(hmr._load = function() {
const app = new Hono;
const port = parseInt(process.env.PORT) || 3000;
const home = app.get("/", (c) => {
return c.json({ message: "Hello World!" });
});
console.log(`Running at http://localhost:${port}`);
var src_default = {
port,
fetch: home.fetch
};
hmr.exportAll({
default: () => src_default
});
})();
var $$hmr_default = hmr.exports.default;
hmr._update = function(exports) {
$$hmr_default = exports.default;
};
export {
$$hmr_default as default
};
//# sourceMappingURL=http://localhost:3000/.map
index.ts 中的原始生成代码为:
import { Hono } from "hono";
const app = new Hono();
const port = parseInt(process.env.PORT) || 3000;
const home = app.get("/", (c) => {
return c.json({ message: "Hello World!" });
});
console.log(`Running at http://localhost:${port}`);
export default {
port,
fetch: home.fetch,
};
我在bun README.md 中没有找到关于bun dev 的文档,但是当创建应用程序时,它会出现一条消息,要求执行“bun dev”而没有其他任何内容,所以我可能遗漏了一些明显的东西。
如何调用运行 bun dev 的 hono API Hello-Word?
另一方面,如果我执行:bun src/index.ts 应用程序按预期工作,但没有热重新加载。
【问题讨论】:
标签: typescript hot-reload bun hono