This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async processHook(hookObject) { | |
for (const entry of hookObject.entry) { | |
for (const change of entry.changes) { | |
this.processEntryChange(change); | |
} | |
} | |
} | |
async processEntryChange(change) { | |
if (change.field !== 'feed') return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post('/webhook', async(req, res) => { | |
const hookObject = req.body; | |
console.log(JSON.stringify(hookObject, null, 2)); | |
await process.processHook(hookObject); | |
res.status(200).send("OK"); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isFlagEnable(flagName) { | |
// Lấy tên, email của người dùng hiện tại | |
const currentUser = userService.getCurrentUser(); | |
// Kiểm tra xem người dùng hiện tại | |
// có được dùng chức năng có tên "flagName" không | |
const flagEnable = flagService.getFlag(flagName, currentUser) | |
return flagEnable | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function showUI() { | |
// Dùng hàm isFlagEnable để lấy giá trị flag, thay vì hardcode | |
const SHOW_NEW_UI = isFlagEnable('show-new-ui'); | |
if (SHOW_NEW_UI) { | |
showPagesV2() | |
} else { | |
showPages() // Show UI cũ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function showPages() { | |
// ... Show UI cũ | |
} | |
function showPagesV2() { | |
// Show UI mới, đang code | |
} | |
// Code cũ, trước khi dùng feature flag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http') | |
const port = 3000 | |
const server = http.createServer((request, response) => { | |
console.log(request.url) | |
response.end('Hello from ToiDiCodeDao') | |
}) | |
server.listen(port, (err) => { | |
if (err) { |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use latest'; | |
import { fromExpress } from 'webtask-tools'; | |
import express from 'express'; | |
import logger from 'morgan'; | |
import cors from 'cors'; | |
import bodyParser from 'body-parser'; | |
import url from 'url'; | |
import axios from 'axios'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<script src="/dist.js"></script> | |
</body> | |
<html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const appName = require('./base'); // Dùng module base.js | |
const { ajax, show } = require('./util'); // Dùng module util.js | |
async function register(username) { | |
// Sử dụng hàm ajax và show của module util | |
await ajax.post('/register', { username }); | |
show(`Welcome ${username} to ${appName}`); | |
} | |
// Các module khác có thể dùng hàm register của module này |