Fresh를 사용한 블로그 엔진: 환경 변수 및 데이터베이스




GitHub: https://github.com/Sokhavuth/deno-fresh
데노 배치: https://khmerweb-fresh.deno.dev/


// setting.js

function setting(){
    const configure = {
        site_title: "Multimedia",
        page_title: "Home",
        message: "",
    }

    return configure
}


import { config } from "config";
await config({export: true});
const secret_key = Deno.env.get("SECRET_KEY");


import { MongoClient } from "mongodb";
const client = await new MongoClient();
await client.connect(Deno.env.get('DATABASE_URI'));
const mydb = client.database(Deno.env.get('DB_NAME'));


import { connect } from "redis"
const myredis = await connect({
    hostname: Deno.env.get('REDIS_URI'),
    port: parseInt(Deno.env.get('REDIS_PORT')),
    password: Deno.env.get('REDIS_PASSWORD'),
});


export { setting, secret_key, mydb, myredis }



// import_map.json
{
  "imports": {
    "$fresh/": "https://deno.land/x/[email protected]/",
    "preact": "https://esm.sh/[email protected]",
    "preact/": "https://esm.sh/[email protected]/",
    "preact-render-to-string": "https://esm.sh/[email protected]?external=preact",
    "setting": "./setting.js",
    "config": "https://deno.land/[email protected]/dotenv/mod.ts",
    "jwt": "https://deno.land/x/[email protected]/mod.ts",
    "mongodb": "https://deno.land/x/[email protected]/mod.ts",
    "redis": "https://deno.land/x/[email protected]/mod.ts",
    "bcrypt": "./bcrypt.ts",
    "cookies": "https://deno.land/[email protected]/http/cookie.ts"
  }
}



// .env

SECRET_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
DATABASE_URI=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
DB_NAME=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
REDIS_URI=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
REDIS_PASSWORD=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
REDIS_PORT=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

좋은 웹페이지 즐겨찾기