-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (24 loc) · 693 Bytes
/
server.js
File metadata and controls
30 lines (24 loc) · 693 Bytes
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
const express = require('express');
const path = require('path');
const compression = require('compression');
const app = express();
const port = 9000;
app.use(compression());
app.use(express.static('./example'));
app.use('/', require('cors')());
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, './', 'index.html'));
});
app.get('/bundle.js', function (req, res) {
res.sendFile(path.join(__dirname, './', 'bundle.js'));
});
// RESTful API
app.get('/api/intro', (req, res) => {
res.json({
name: 'yingray',
msg: 'hello world!'
});
});
app.listen(port, () => {
console.log(`Listening on port ${port} (http://localhost:${port})`);
});