-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
63 lines (49 loc) · 1.91 KB
/
server.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"use strict";
require('dotenv').config(); // loads environment variables from .env file into process.env
const PORT = process.env.PORT || 8080;
const ENV = process.env.ENV || "development";
const express = require("express");
const bodyParser = require("body-parser");
const sass = require("node-sass-middleware");
const app = express();
const bcrypt = require('bcryptjs');
const cookieSession = require('cookie-session');
const knexConfig = require("./knexfile");
const knex = require("knex")(knexConfig[ENV]);
const morgan = require('morgan');
const knexLogger = require('knex-logger');
const request = require ('request');
const categorize = require("./public/scripts/categorize.js")
// Seperated Routes for each Resource
const usersRoutes = require("./routes/users");
const activityRoutes = require("./routes/activity");
// Load the logger first so all (static) HTTP requests are logged to STDOUT
// 'dev' = Concise output colored by response status for development use.
// The :status token will be colored red for server error codes, yellow for client error codes, cyan for redirection codes, and uncolored for all other codes.
app.use(morgan('dev'));
// Log knex SQL queries to STDOUT as well
app.use(knexLogger(knex));
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieSession({
name: 'session',
keys: ['key']
}))
app.use("/styles", sass({
src: __dirname + "/styles",
dest: __dirname + "/public/styles",
debug: true,
outputStyle: 'expanded'
}));
app.use(express.static("public"));
// Mount all resource routes
app.use("/", usersRoutes(knex));
// mount all routes that retrieves activities from database
app.use("/activity", activityRoutes(knex));
// // Home page
// app.get("/", (req, res) => {
// res.render("index");
// });
app.listen(PORT, () => {
console.log("Example app listening on port " + PORT);
});