33 lines
941 B
TypeScript
33 lines
941 B
TypeScript
import express, { Request, Response, Router, Express } from "express";
|
|
import bodyParser from "body-parser";
|
|
import router from "./route";
|
|
import { default as paginate } from "express-paginate";
|
|
|
|
// call express
|
|
const app: Express = express(); // define our app using express
|
|
|
|
// configure app to use bodyParser for
|
|
// Getting data from body of requests
|
|
app.use(bodyParser.json());
|
|
app.use(paginate.middleware(10, 50));
|
|
|
|
app.use(bodyParser.urlencoded({ extended: true }));
|
|
|
|
const port: number = Number(process.env.PORT) || 8050; // set our port
|
|
|
|
// Send index.html on root request
|
|
app.use(express.static("dist"));
|
|
|
|
app.get("/", (req: Request, res: Response) => {
|
|
console.log("sending index.html");
|
|
res.sendFile("/dist/index.html");
|
|
});
|
|
|
|
// REGISTER ROUTES
|
|
// all of the routes will be prefixed with /api
|
|
const routes: Router[] = Object.values(router);
|
|
app.use("/api", routes);
|
|
|
|
app.listen(port);
|
|
console.log(`App listening on ${port}`);
|