0

控制器/products.ts

import { Product } from "../types.ts";


let products: Product[] = [
    {
        id: "1",
        name: "Product One",
        description: "This is product one",
        price: 29.99,
    },
    {
        id: "2",
        name: "Product Two",
        description: "This is product two",
        price: 39.99,
    },
    {
        id: "3",
        name: "Product Three",
        description: "This is product three",
        price: 59.99,
    },
];

export const getProducts = ({ response }: { response: any }) => {
    response.body = {
        success: true,
        data: products
    }
}

路线.ts

import { Router } from "https://deno.land/x/oak/mod.ts";
import { getProducts } from "./controllers/products.ts";

const router = new Router()

router.get('/api/v1/products', getProducts)

export default router;

服务器.ts

import { Application } from "https://deno.land/x/oak/mod.ts";
import router from './routes.ts';

const app = new Application()
console.log(`Server running on http://localhost:5000`);

app.use(router.routes())
app.use(router.allowedMethods())

await app.listen({ port: 5000 })

我一直在尝试使用命令行中的命令运行文件server.ts

deno run --allow-net server.ts

我得到的只是命令行错误

fish: “deno run server.ts” terminated by signal SIGSEGV (Address boundary error)

Everyting 工作正常。突然开始不行了

4

0 回答 0