-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
48 lines (40 loc) · 1.22 KB
/
app.js
File metadata and controls
48 lines (40 loc) · 1.22 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
import express from 'express'
import student from './student.json'
import { version } from 'punycode';
import _ from 'lodash';
import studentRoute from './studentRoute';
import morgan from 'morgan';
import bodyParser from 'body-parser';
import path from 'path';
import https from 'https';
import fs from 'fs';
const PORT = 8080;
const SLPORT = 8082;
const server = express();
const buildUrl = (path) => `/${path}`;
const studentUrl = buildUrl('student');
const slOptions = {
key: fs.readFileSync(path.join('key.pem')),
cert: fs.readFileSync(path.join('cert.pem')),
passphrase: '123456'
};
server.use(morgan('tiny'));
server.use(bodyParser.json());
server.use(express.static('public'));
server.use(studentUrl, studentRoute);
server.set('views', path.join('views'));
server.set('view engine', 'ejs');
server.get('/', (req,res) => {
res.render('index', {
student: student
});
});
server.get('/download/images/:imgName', (req,res) => {
res.download(path.join('public', 'images', req.params.imgName));
});
server.listen(PORT, () =>{
console.log(`Server is up on port ${PORT}...`);
});
https.createServer(slOptions, server).listen(SLPORT, () => {
console.log(`Secure Server is up on port ${SLPORT}...`)
});