-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (29 loc) · 769 Bytes
/
index.js
File metadata and controls
34 lines (29 loc) · 769 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
31
32
33
34
// basic express server
const express = require('express');
const fs = require('fs');
const app = express();
const cors = require('cors');
const port = 8080;
app.use(cors());
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.get('/vmap', (req, res) => {
// readfile content as string
const vmap = fs.readFileSync('./vmap.xml', 'utf8');
//set header as xml
res.set('Content-Type', 'application/xml');
res.send(vmap);
});
// add cors support
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept'
);
next();
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});