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
// 案例一:toJSON() | |
const data = tweets.map(t => ({ | |
...t.toJSON(), | |
})) | |
// 改為使用下面的參數 | |
const tweets = await Tweet.findAll({ | |
nest: true, | |
raw: true, | |
}) |
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
import http from "k6/http"; | |
import { sleep } from "k6"; | |
export default function() { | |
http.get("http://localhost:3000"); | |
sleep(1); | |
} |
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 requests = []; | |
http.createServer((request, response) => { | |
requests.push(request) | |
response.writeHead(200, {'Content-Type': 'text/plain'}); | |
response.end('Hello World\n'); | |
}).listen(3000); |
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
<?php | |
class SortableArray { | |
private $content; | |
private $length; | |
function __construct(int ...$items) { | |
$this->content = $items; | |
$this->length = count($items); | |
} |
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
// src/routes/auth.route.ts | |
import {loginRequest} from "../requests/AuthRequest"; | |
protected setRoutes() { | |
this.router.post('/login', loginRequest, this.authController.echo); | |
} |
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
import {validationResult} from "express-validator"; | |
export function showApiError(req: Request, res: Response, next: NextFunction) { | |
const errors = validationResult(req); | |
if (!errors.isEmpty()) { | |
return res.status(400).json({ errors: errors.array() }); | |
} | |
next(); | |
} |
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
// src/requests/AuthRequest.ts | |
import {check} from "express-validator"; | |
import {showApiError} from "../middleware/AuthMiddleware"; | |
export const loginRequest = [ | |
check('username').exists().isLength({min: 4}), | |
check('password').exists().isLength({min: 4}), | |
showApiError | |
]; |
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
// src/app.ts | |
app.use(AuthMiddleware); |
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
// src/routes/auth.route.ts | |
this.router.use(AuthMiddleware); |
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
// src/routes/auth.route.ts | |
this.router.get('/login', AuthMiddleware, this.authController.echo); |
NewerOlder