general

Lấy đường dẫn thư mục đầu tiên

application.arrFolder

helmet.xframe

app.use(helmet.xframe()) -> app.use(helmet.frameguard());

app.use(helmet.xssFilter());
app.use(helmet.noSniff());
app.use(helmet.ieNoOpen());

Authenticate

  • Set authenticate for page
get : {
    handler : component.controllers.index,
    authenticate : true
}
  • Chọn phương thức đăng nhập (local, facebook, google,..) đc lấy trong file ./config/passport.js
post : {
    authenticate: 'local1'
}

Flash

  • Sử dụng
req.flash.success('Register successfully');
res.render('create', { failure: req.session.flash.error, success: req.session.flash.success });
  • Phương thức
req.flash.success
req.flash.error
req.flash.warn
req.flash.info

Theme view

  • Set theme view
view : {
    path :{
        folder : ["/public/themes/:theme","view"]
    }
},
  • Set multi theme view
view: [
    {
        path: {
            name: 'backend',
            folder: [
                '/themes/backend/:backendTheme/features/$component',
                'backend/views',
                '/themes/backend/:backendTheme/layouts'
            ]
        }
    },
    {
        path: {
            name: 'frontend',
            folder: [
                '/themes/frontend/:frontendTheme/features/$component',
                'frontend/views',
                '/themes/frontend/:frontendTheme/features/$component'
                //'/themes/frontend/:frontendTheme/layouts'
            ]
        }
    }
],

Change theme

let theme = req.query.theme || "clean";
application.setConfig("theme",theme).then(function () {
    res.render('change', {theme: application.getConfig('theme')});
});

Upload file

  • Download file
res.download(uploadPath + req.params.file, function (err) {
    if (!err) 
        return; // file sent

    if (err && err.status !== 404) 
        return next(err); // non-404 error

    // file for download not found
    res.statusCode = 404;
    res.send('Cant find that file, sorry!');
});
  • Delete file
fs.unlink(uploadPath + req.params.file, function () {
    res.redirect('/');
});
  • List file từ folder
let data = [];
fs.readdir(uploadPath, function (err, listFiles) {
    if (listFiles === undefined) {
        fs.emptyDir(uploadPath, function (err) {
            if (!err) console.log('success!')
        });
    }
    for (let item in listFiles) {
        let info = {};
        let stats = fs.statSync(uploadPath + listFiles[item]);
        let fileSizeInBytes = stats["size"];
        let fileSizeInKilobytes = fileSizeInBytes / 1024;
        let datetime = new Date(stats["birthtime"]);
        info["name"] = listFiles[item];
        info["size"] = Math.ceil(fileSizeInKilobytes);
        info["birthtime"] = datetime.getDate() + "/" + (datetime.getMonth() + 1) + "/" + datetime.getFullYear();
        data.push(info);
    }
    res.render('index', {
        data: data
    });
});
  • Upload file
let form = new formidable.IncomingForm();
form.uploadDir = uploadPath;
form.keepExtensions = true;

form.parse(req, function (err, fields, files) {
    //res.writeHead(200, {'content-type': 'text/plain'});
    //res.write('received upload:\n\n');
    //res.end(util.inspect({fields: fields, files: files}));
});

form.on('progress', function (bytesReceived, bytesExpected) {
    let percent_complete = (bytesReceived / bytesExpected) * 100;
    let progress = percent_complete.toFixed(2);
    console.log("--> ", progress);
});

form.on('fileBegin', function (name, file) {
    // update name file
    file.path = uploadPath + file.name;
    res.redirect('/');
});

Error: application.setConfig is not a function

server.js

application.start({
    port: 3333
});

node_modules/arrowjs/libs/ArrowApplication.js, trong start(settings), dòng 243, thêm code

if(typeof setting !== 'undefined' && setting.port) {
    self.setConfig('port', setting.port);
}
    ├── handleAttribute
    ├── helper
    ├── ConfigManager.js
    ├── DefaultManager.js
    └── SystemManager.js
## handleAttribute
Lấy tất cả action/controller/... được khai báo trong config/structure.js để có thể lấy được các function trong đó.
Các functions sẽ được lưu vào mảng Obj.

- action.js : Lấy tất cả actions
- controller.js : Lấy tất cả controllers
- extends.js : Lấy tất cả extends
- handleFunction.js : Mỗi file action.js, controller.js,... là 1 function nên ta sẽ gộp tất cả vào 1 file để sau này cần thì cứ gọi file này.
- model.js : Lấy tất cả models
- other.js : ko su dung
- path.js : Lấy tất cả path
- route.js : Lấy tất cả route
- view.js : Tìm folder chứa view

## helper 
- getListFile.js : Lấy danh sách file bởi Glob (ở đây sẽ lấy các file .js)
- getListFolder.js : lấy tất cả đường dẫn folder từ cấu hình trong config/structure.js (VD: views, controller, model)
- getListFunction.js : Lấy tất cả function từ config/structure.js

## general
- ConfigManager.js (Thêm, sửa, xóa cầu hình, cache)
    + GetConfig
    + UpdateConfig
    + SetConfig
    + getCache
    + SetCache
    + reload

- DefaultManager.js

- SystemManager.js (Khi chạy server sẽ lưu vào json)
    + getCache : Lấy tất cả config từ cache
    + setCache : Set tất cả config vào cache
    + reload: Nhận dữ liệu từ cache 
    + loadComponents: Load views, controllers và models của 1 featured
    + getPermissions: Lấy quyền truy cập của 1 feature hoặc tất cả feature
    + getAttribute: Lấy thuộc tính của feature
    + getViewFiles: Lấy tất cả file view (Đường dẫn các file đc cấu hình trong config/structure.js)
    + getComponent: Lấy thông tin component
    + handleView: Xử lý view
    + makeRender: Quản lý view
    + getInfo: -----------------------

results matching ""

    No results matching ""