forked from RoyTakanen/BitGallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
86 lines (58 loc) · 2.21 KB
/
app.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
require('dotenv').config()
const express = require('express')
const randomstring = require("randomstring");
const fileUpload = require('express-fileupload');
const mime = require('mime-types')
const { Sequelize, Model, DataTypes } = require("sequelize");
const bodyParser = require('body-parser');
const bcrypt = require('bcrypt');
const session = require('express-session')
const cors = require('cors');
const frontPage = require('./routes/frontPage')
const { loginGet, loginPost } = require('./routes/login')
const { registerGet, registerPost } = require('./routes/register')
const logout = require('./routes/logout')
const upload = require('./routes/api/upload')
const { redirectToFrontPage } = require('./routes/other')
let hcaptchaEnabled = false
if (process.env.HCAPTCHA_SECRET_KEY != "") {
const {verify} = require('hcaptcha');
const SECRET = process.env.HCAPTCHA_SECRET_KEY;
hcaptchaEnabled = true
console.log('hCaptcha has been enabled.')
}
const app = express()
const port = process.env.PORT || 8989
const saltRounds = 10;
const serviceUrl = `${(process.env.SSL != "" ? "https" : "http")}://${process.env.HOSTNAME}${["80", "443"].includes(port) ? "" : ":" + port}/${process.env.WEB_PATH}`
const sequelize = new Sequelize('sqlite::memory:')
app.use(session({
secret: 'keyboard cat'
}))
const User = sequelize.define("user", {
username: DataTypes.TEXT,
password: DataTypes.TEXT
});
const Image = sequelize.define("image", {
filename: DataTypes.TEXT,
owner: DataTypes.TEXT
});
sequelize.sync();
const allowedMimes = ["image/jpeg", "image/png"]
app.set('view engine', 'ejs');
app.use('/i', express.static('images'))
app.use(fileUpload());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.get('/', frontPage);
app.get('/login', loginGet);
app.get('/register', registerGet);
app.get('/logout', logout);
app.post('/login', loginPost);
app.post('/register', registerPost);
app.post('/api/upload', upload);
app.get('*', redirectToFrontPage);
//`${process.cwd()}/images/${files.fileInput.name}`
app.listen(port, () => {
console.log(`BitGallery listening at ${serviceUrl}`)
})