forked from STICKEREST/stickerest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
54 lines (36 loc) · 1.36 KB
/
app.ts
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
import express, { Express } from 'express';
import bodyParser from 'body-parser';
import expressFileUpload from 'express-fileupload';
import { initDb, getDb, Database } from './db';
import usersRoutes from './routes/users.routes';
import stickersRoutes from './routes/stickers.routes';
import auth from './routes/auth/auth.routes';
import passport from 'passport';
import { setupPassport } from './middlewares/passport.middleware';
import {sessionMiddleware, checkAuthentication} from './middlewares/session.middleware';
var fs = require('fs');
const dir = './public/files/temp';
const outputDir = './public/files/output/';
if (!fs.existsSync(dir)){
fs.mkdirSync(dir, { recursive: true });
}
if (!fs.existsSync(outputDir)){
fs.mkdirSync(outputDir, { recursive: true });
}
require('dotenv').config();
const app: Express = express();
const port = process.env.PORT || 5000;
setupPassport();
const connection : Database = getDb();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(sessionMiddleware);
app.use(passport.initialize());
app.use(passport.session());
app.use(expressFileUpload());
app.use('/users', usersRoutes);
app.use('/stickers', stickersRoutes);
app.use('/auth', checkAuthentication, auth);
app.get('/', (req, res) => res.send('Hello from Homepage') );
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})