Created
January 17, 2019 03:59
-
-
Save choonewza/8b3866d2e3d87201dfbbbbd02cc6e82c to your computer and use it in GitHub Desktop.
stm32lora_loraiot_ep3-server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const morgan = require("morgan"); | |
const compression = require("compression"); | |
const bodyParser = require("body-parser"); | |
const cookieSession = require("cookie-session"); | |
// const passport = require("passport"); | |
const keys = require("./config/keys"); | |
//Services | |
require("./services/mongoose"); | |
// require("./services/passport"); | |
const app = express(); | |
if (process.env.NODE_ENV == "production") { | |
app.use(compression()); | |
} else { | |
app.use(morgan("dev")); | |
} | |
app.use( | |
cookieSession({ | |
maxAge: 30 * 24 * 60 * 60 * 1000, //30 days | |
keys: [keys.cookieKey] | |
}) | |
); | |
// app.use(passport.initialize()); | |
// app.use(passport.session()); | |
app.use( | |
bodyParser.urlencoded({ | |
extended: true | |
}) | |
); | |
app.use(bodyParser.json()); | |
//Routes | |
// require("./app/routes/authRoutes")(app); | |
require("./app/routes/loraiotRoutes")(app); | |
if (process.env.NODE_ENV === "production") { | |
//Express will serve up production assets | |
//like our main.js file, or main.css file! | |
app.use(express.static("client/build")); | |
//Express will serve up the index.html file | |
//if it doesn't recognize the route | |
const path = require("path"); | |
app.get("*", (req, res) => { | |
res.sendFile(path.resolve(__dirname, "client", "build", "index.html")); | |
}); | |
} | |
const PORT = process.env.PORT || 5000; | |
app.listen(PORT, function() { | |
console.log(`Server Running at http://localhost:${PORT}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment