[ Home ]
back

bolt.new 生成、TODO 修正+ d1 database連携

id: 177, 2024-10-17

概要:

bolt.new生成後、なかなかAI修正進まない部分を。自作で修正する内容です

  • TODOデータを、d1 + CF workers連携します。

[ 公開日: 2024/10/16 ]


構成

  • CF-workers
  • D1 database
  • bolt.new
  • shadcn/ui
  • Express.js
  • esbuild
  • typescript

作成したコード

https://github.com/kuc-arc-f/bolt_5example


dev-start

bun run build
bun run dev


....
router.post("/create", async function(req: any, res: any) {
  const retObj = {ret: 500 , message: "" }
  try {
    if(!req.body){
      throw new Error("nothing, body");
    }
    const body = req.body;
console.log(req.body);
    const url = process.env.EXTERNAL_API_URL; 
    const path = "/test/create";	
console.log("path=", url + path);
    body.title = body.text;
    const response = await axios.post(url + path, body, 
    {headers: { "Content-Type": "application/json"}
    });
console.log(response.data);
    retObj.ret = 200;
    retObj.data = response.data.data;
    return res.json(retObj);
  } catch (error) {
    console.error(error);
    res.sendStatus(500);
  }
});

/**
* 
* @param
*
* @return
*/ 
router.post("/get_list", async function(req: any, res: any) {
  const retObj = {ret: 500 , message: "" }
  //
  try {
    const url = process.env.EXTERNAL_API_URL; 
    const path = "/test/get_list";	
console.log("path=", url + path);
    const response = await axios.post(url + path, req.body, 
      {headers: { "Content-Type": "application/json"}
    });
    //console.log(response.data);
    retObj.ret = 200;
    retObj.data = response.data.data;
    const out  = todoData.convertTextArray(retObj.data);
    //console.log(out);
    retObj.data = out;
    return res.json(retObj);
  } catch (error) {
    console.error(error);
    res.sendStatus(500);
  }
});

  • 画面側は、前回内部API連携済なので。修正は、ほぼ無し。