Repository navigation
Expand file tree
/
Copy pathapp.ts
More file actions
59 lines (49 loc) · 1.56 KB
/
Copy pathapp.ts
File metadata and controls
59 lines (49 loc) · 1.56 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
48
49
50
51
52
53
54
55
56
57
58
59
import express, { Request, Response } from "express";
import { MyDataSource } from "./ormconfig";
import path from 'path';
import "reflect-metadata"
import cors from 'cors';
import bodyParser from "body-parser";
import helmet from "helmet";
import Moralis from "moralis";
const compression = require('compression');
const cookieParser = require("cookie-parser");
const hpp = require('hpp');
import { accountRouter } from "./api/routes/account";
import { testAPIRouter } from "./api/routes/testAPI";
import { blockchainRouter } from "./api/routes/blockchain";
import { HOST, PORT, MORALIS_API_KEY } from './config';
import { ProfileRouter } from "./api/routes/profile";
const app = express();
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "build")));
app.use(bodyParser.json());
app.use(
cors({
origin: `http://${HOST}:3000`,
credentials: true,
}));
app.use(helmet());
app.use(hpp());
app.use(compression());
app.use("/api", accountRouter);
app.use("/api/profile", ProfileRouter);
app.use("/api/blockchain", blockchainRouter)
app.use("/~testAPI", testAPIRouter);
//? custom 404 not found
app.get('*', (_req: Request, res: Response) => {
return res.status(404).sendFile(path.join(__dirname, 'build/index.html'));
});
const startServer = async () => {
await Moralis.start({
apiKey: MORALIS_API_KEY,
});
//? starting webApp
MyDataSource.initialize().then(() => {
app.listen(PORT, HOST, () => {
console.log(`Web App listening at http://${HOST}:${PORT}`)
});
});
};
startServer()
export default app;