-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (52 loc) · 2.19 KB
/
index.js
File metadata and controls
63 lines (52 loc) · 2.19 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const express = require("express");
const bodyParser = require("body-parser");
const authentication_routes = require("./routes/auth");
const users_routes = require("./routes/users");
const questions_routes = require("./routes/questions");
const topics_routes = require("./routes/topics")
const question_comments_routes = require("./routes/question_comments");
const answers_routes = require("./routes/answers");
const answer_comments_routes = require("./routes/answer_comments");
const cors = require('cors');
require("./config/database_config");
const app = express();
const port = process.env.PORT || 3000;
app.listen(port,()=>console.log(`listening at ${port}`));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cors())
app.use("/auth", authentication_routes);
app.use("/users", users_routes);
app.use("/questions", questions_routes);
app.use("/topics", topics_routes);
app.use("/questioncomments", question_comments_routes);
app.use("/answers", answers_routes);
app.use("/answercomments", answer_comments_routes);
// let endpoints = [];
// function print (path, layer) {
// if (layer.route) {
// layer.route.stack.forEach(print.bind(null, path.concat(split(layer.route.path))))
// } else if (layer.name === 'router' && layer.handle.stack) {
// layer.handle.stack.forEach(print.bind(null, path.concat(split(layer.regexp))))
// } else if (layer.method) {
// let route = layer.method.toUpperCase() + '/' + path.concat(split(layer.regexp)).filter(Boolean).join('/');
// if(!endpoints.includes(route))endpoints.push(route);
// }
// }
// function split (thing) {
// if (typeof thing === 'string') {
// return thing.split('/')
// } else if (thing.fast_slash) {
// return ''
// } else {
// var match = thing.toString()
// .replace('\\/?', '')
// .replace('(?=\\/|$)', '$')
// .match(/^\/\^((?:\\[.*+?^${}()|[\]\\\/]|[^.*+?^${}()|[\]\\\/])*)\$\//)
// return match
// ? match[1].replace(/\\(.)/g, '$1').split('/')
// : '<complex:' + thing.toString() + '>'
// }
// }
// app._router.stack.forEach(print.bind(null, []))
// endpoints.forEach(r => console.log(r))