forked from Azure/azure-resource-manager-schemas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
25 lines (18 loc) · 679 Bytes
/
server.ts
File metadata and controls
25 lines (18 loc) · 679 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
import express = require('express');
import { promisify } from 'util';
import { hostname } from 'os';
import fs from 'fs';
const readFile = promisify(fs.readFile);
const app = express();
const port = 3000;
app.use("/schemas", async (req, res) => {
try {
let file = await readFile(__dirname + '/../schemas' + req.path, { encoding: 'utf8'});
file = file.replace(/https:\/\/schema\.management\.azure\.com\/schemas\//g, `http://${hostname()}:${port}/schemas/`);
res.header('Content-Type', 'application/json');
res.send(file);
} catch (err) {
res.sendStatus(404);
}
});
app.listen(port, () => console.log(`Listening on http://${hostname()}:${port}`));