-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.ts
More file actions
56 lines (54 loc) · 1.39 KB
/
server.ts
File metadata and controls
56 lines (54 loc) · 1.39 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
//import express
import * as express from "express";
import {Request, Response} from "express";
const app = express()
//import CORS
const cors = require("cors")
//import db accessories
import User from "./entities/User";
import { DataSource } from "typeorm";
//Connecting to database
export const myAppDataSource = new DataSource({
type: "postgres",
host: "localhost",
port: 5432,
username: "postgres",
password: "changeme",
database: "postgres",
synchronize: true,
logging: true,
entities: [User],
subscribers: [],
migrations: [],
})
//Initializing the database
myAppDataSource.initialize()
.then(() => {
console.log("Data Source has been initialized!")
})
.catch((err) => {
console.error("Error during Data Source initialization", err)
})
//config env
import "dotenv/config"
//Middleware
//Cors
app.use(cors())
//Parsing json reqs
app.use(express.json())
//Routes
import authentication from "./routes/authentication";
import authorization from "./routes/authorization";
import posts from "./routes/posts";
import fileUpload from "./routes/file-upload";
//regular routes
app.use(authentication)
app.use(authorization)
// Protected Route
app.use("/api/", posts)
//file upload
app.use("/upload", fileUpload)
//Running Server
app.listen(process.env.SERVER_PORT, () => {
console.log(`Server Running on port: ${process.env.SERVER_PORT}`)
})