generated from dhmmasson/template-webapp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.mjs
84 lines (73 loc) · 2.04 KB
/
app.mjs
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {
autoLocals,
autoRoute,
mysqlConnector,
updateTemplate,
} from "./src/expressUtils/index.mjs";
import cookieParser from "cookie-parser";
import { SetUpEnvironment } from "./src/secrets.mjs";
import errorHandler from "./routes/_error.js";
import express from "express";
import logger from "morgan";
import path from "path";
//import sassMiddleware from "node-sass-middleware" ;
await SetUpEnvironment();
const app = express();
if (app.get("env")) app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
/** Use scss on demand */
// app.use( sassMiddleware(
// { src : path.join( process.cwd(), "public" )
// , dest : path.join( process.cwd(), "public" )
// , indentedSyntax : false // .scss
// , sourceMap : true
// } ) ) ;
updateTemplate(
path.resolve(process.cwd(), "views/partials"),
path.resolve(process.cwd(), "public/javascripts")
);
/** Static routes : css, images, and app js*/
app.use(express.static(path.join(process.cwd(), "public")));
/** Static routes : libraries */
app.use(
"/javascripts",
express.static(path.join(process.cwd(), "node_modules/jquery/dist"))
);
app.use(
"/javascripts",
express.static(
path.join(process.cwd(), "node_modules/materialize-css/dist/js")
)
);
app.use(
"/javascripts",
express.static(
path.join(process.cwd(), "node_modules/@svgdotjs/svg.draggable.js/dist")
)
);
app.use(
"/javascripts",
express.static(path.join(process.cwd(), "node_modules/@svgdotjs/svg.js/dist"))
);
app.use(
"/javascripts",
express.static(path.join(process.cwd(), "node_modules/papaparse"))
);
app.use(
"/fonts",
express.static(
path.join(process.cwd(), "node_modules/materialize-css/dist/fonts")
)
);
/** Autoloading routes */
app.set("views", path.join(process.cwd(), "views"));
app.set("view engine", "pug");
app.locals = autoLocals();
app.use(autoRoute());
// create a database connector
app.set("connector", mysqlConnector());
/** Error handling */
app.use(errorHandler);
export default app;