generated from salacryl/base_nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
71 lines (58 loc) · 1.54 KB
/
index.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
64
65
66
67
68
69
70
71
/* global __dirname */
/* global process */
import express from "express";
import { createLogger, format, transports, } from "winston";
import exphbs from "express-handlebars";
import bodyParser from "body-parser";
import methodOverride from "method-override";
import browserSync from "browser-sync";
import path from "path";
// init logger
const logger = createLogger({
format: format.combine(
format.splat(),
format.simple()
),
transports: [new transports.Console(),],
});
// Get Port
const PORT = process.env.PORT || 5000;
const ENV = process.env.APP_ENV || "dev";
// init App
const app = express();
// init view engine
app.engine("handlebars", exphbs({defaultLayout: "main",}));
app.set("view engine", "handlebars");
// body-parser
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true, }));
// Method-Override
app.use(methodOverride("_method"));
// publish public folder
app.use(express.static(path.join(__dirname, "/public")));
// default route
app.get("/", (req, res) => {
res.render("homepage", {greeting: "Salacryl's starting project",});
});
app.get("/three", (req, res) => {
res.render("three");
});
app.listen(PORT, () => logger.log("info", "Webservice startet on Port: %d", PORT));
// init browser-sync
logger.log("info", "ENV ist: %s", ENV);
if (ENV==="dev"){
const bs = browserSync.create();
bs.init({
port: PORT+1,
proxy: {
target: "localhost:" + PORT,
},
files: [
{
match: ["./public/**/*.*", "./views/**/*.*", "./views/*.*"],
fn: function (event, file) {
this.reload()
}
}],
});
}