123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- const express = require("express");
- const path = require("path");
- const app = express();
- const morgan = require("morgan");
- const socketio = require("socket.io");
- const pg = require("pg");
- delete pg.native;
- const db = require("./db");
- const chalk = require("chalk");
- const PORT = process.env.PORT || 3500;
- app.use(morgan("dev"));
- app.use(express.json());
- app.use(express.urlencoded({ extended: true }));
- app.use(require("body-parser").text());
- app.use(
- "/static",
- express.static(path.resolve(__dirname, "..", "build", "static"))
- );
- app.get("/manifest.json", (req, res) => {
- res.sendFile(path.resolve(__dirname, "..", "build", "manifest.json"));
- });
- app.get("/favicon.png", (req, res) => {
- res.sendFile(path.resolve(__dirname, "..", "build", "favicon.png"));
- });
- app.use("*", express.static(path.resolve(__dirname, "..", "build")));
- app.use((err, req, res, next) => {
- console.error(err);
- console.error(err.stack);
- res.status(err.status || 500).send(err.message || "Internal server error.");
- next();
- });
- const startListening = () => {
- const server = app.listen(PORT, () => {
- console.log(chalk.blue(`[Express] Listening on port ${PORT}`));
- });
- const io = socketio(server);
- require("./socket")(io);
- };
- const startApp = async () => {
-
- await startListening();
- };
- startApp();
|