-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
48 lines (36 loc) · 1.07 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
// Config
const cfg = require('./config');
// Basic express stuff
const express = require('express');
const parser = require('cookie-parser');
const exphbs = require('express-handlebars');
// App
const app = express();
module.exports = app;
app.use(parser());
// Render
app.engine('handlebars', exphbs());
app.set('views', `${__dirname}/src/views`);
app.set('view engine', 'handlebars');
app.disable('x-powered-by');
app.disable('etag');
// Route function for shortening purposes (no pun intended)
const route = file => require(`./src/routes/${file}`);
// Load DB
require('./src/utils/database');
/* Route */
// Shortened link
app.get('/random', route('random'));
app.get('/:link', route('link.js'));
// API/AJAX
app.get('/api/:link', route('api'));
app.get('/links', route('links'));
app.get('/new', route('new'));
// Visible
app.get('/big/:link', route('big'));
app.get('/qr/:link', route('qr'));
app.get('/', route('shortener'));
/* Route */
// Static Files
app.use(express.static(`${__dirname}/src/public`));
app.listen(cfg.port, () => console.log(`Listening on port ${cfg.port}`));