-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapiRouter.js
43 lines (35 loc) · 1010 Bytes
/
apiRouter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env node
"use strict";
const {
readFileSync,
readFile,
stat,
createReadStream,
} = require("fs");
const {
join,
extname
} = require("path");
const { promisify } = require("util");
const Router = require("koa-router");
const __readFile = promisify(readFile);
// const authorize = require(`${__dirname}/middleware/authorize`);
// const session = require(`${__dirname}/middleware/session`);
const adminAuth = require(`${__dirname}/middleware/adminAuth`);
const userAuth = require(`${__dirname}/middleware/userAuth`);
const apiRouter = new Router();
module.exports = apiRouter;
apiRouter.use(`/api`, userAuth());
apiRouter.use(`/api/admin`, adminAuth());
apiRouter.post(`/api/login`, loginRouteHandler);
apiRouter.get("/api/hello", pingRouteHandler);
function loginRouteHandler (ctx, next, ...args) {
ctx.status = 200;
ctx.body = "OK";
}
function pingRouteHandler (ctx, next, ...args) {
console.log("hellooooooooo");
// ctx.router available
ctx.status = 200;
ctx.body = "hellooo";
}