-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
47 lines (32 loc) · 1.24 KB
/
server.js
File metadata and controls
47 lines (32 loc) · 1.24 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
const express = require("express");
const path = require("path");
const http = require("http");
const bodyParser = require("body-parser");
const passport = require("passport");
// API Routes
const api = require("./server/routes/api");
const app = express();
require("dotenv").config();
// Parser for the post data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
// Cors
app.use(require("cors")());
// Passport
app.use(passport.initialize());
app.use(passport.session());
require("./server/config/passport")(passport);
//Point static path to dist
app.use(express.static(path.join(__dirname, "public")));
app.get("/ref/:username", (request, response) => {
return response.redirect(`https://play.google.com/store/apps/details?id=com.thestorytab.thestorytab&referrer=utm_source%3Dreferral%26utm_content%3${request.params.username}`);
});
app.use("/api/v1", api);
app.use("/api/**", (request, response) => response.status(404).send("Not Found"));
app.get("**", (req, response) => {
response.sendFile(path.join(__dirname, "public", "index.html"));
});
const PORT = process.env.PORT || 3001;
app.set("port", PORT);
const server = http.createServer(app);
server.listen(PORT, () => console.log(`Server is running at ${PORT}`));