Does node+koa need to change the path path of cookie according to the requested interface?

Startup file

app.js

let cookie = {
    maxAge: new Date().getTime() + 3*24*3600*1000, // cookie
    expires: new Date().getTime() + 3*24*3600*1000,  // cookie
    path: "/", // cookie
    domain: "127.0.0.1", // cookie
    httpOnly: true, // http
    overwrite: false,  // 
    signed: true,
    rolling: false
}

main operation interface data source

servse.js

async login (ctx) {
        let user_password = ctx.request.body,
            password = md5(user_password.password),
            select_user_password = `SELECT * FROM customer WHERE username = "${user_password.user}" AND password = "${password}"`;
        try {
            let islogin = await query(select_user_password);
            if(islogin.length > 0) {
                ctx.session = {
                    user_id: islogin[0].id,
                    isLogin: true,
                    username: islogin[0].username,
                }
            }
            ctx.response.body = {
                status: 200,
                description: "ok",
                result: islogin.length > 0 ? true : false
            }
        } catch (err) {
            ctx.response.body = {
                result: false
            }
        }
    }
Apr.09,2021

if you have different subprojects under a project that need different path to distinguish, you need

generally speaking, if an interface corresponds to only one project, you can use / directly

.
Menu