UNPKG

3.57 kBJavaScriptView Raw
1
2const fsw = require('../fsw');
3const swu = require('../swu');
4
5const fs = require('fs');
6const http = require('http');
7const url = require('url');
8const prefix = '<?xml version="1.0" standalone="no"?>\n';
9
10const server = http.createServer((request, response) => {
11 const parsed = url.parse(request.url);
12 const parts = decodeURIComponent(parsed.pathname).split('/');
13 const label = parts.slice(1, 4).join('-');
14 switch (label) {
15 case "fsw-symbol-svg":
16 fsw.symbolSvg(parts[4]).then( res => {
17 response.writeHead(200, { "Content-Type": "image/svg+xml; charset=utf-8" })
18 response.write(prefix)
19 response.write(res)
20 response.end();
21 })
22 break;
23 case "fsw-symbol-png":
24 fsw.symbolPng(parts[4]).then( res => {
25 response.writeHead(200, { "Content-Type": "image/png" })
26 response.write(res)
27 response.end();
28 })
29 break;
30 case "fsw-symbol-normalize":
31 fsw.symbolNormalize(parts[4]).then( res => {
32 response.writeHead(200, { "Content-Type": "text/plain; charset=utf-8" })
33 response.write(res || "")
34 response.end();
35 })
36 break;
37 case "fsw-sign-svg":
38 fsw.signSvg(parts[4]).then ( res => {
39 response.writeHead(200, { "Content-Type": "image/svg+xml; charset=utf-8" })
40 response.write(prefix)
41 response.write(res)
42 response.end();
43 })
44 break;
45 case "fsw-sign-png":
46 fsw.signPng(parts[4]).then ( res => {
47 response.writeHead(200, { "Content-Type": "image/png" })
48 response.write(res)
49 response.end();
50 })
51 break;
52 case "fsw-sign-normalize":
53 fsw.signNormalize(parts[4]).then ( res => {
54 response.writeHead(200, { "Content-Type": "text/plain; charset=utf-8" })
55 response.write(res)
56 response.end();
57 })
58 break;
59 case "swu-symbol-svg":
60 swu.symbolSvg(parts[4]).then ( res => {
61 response.writeHead(200, { "Content-Type": "image/svg+xml; charset=utf-8" })
62 response.write(prefix)
63 response.write(res)
64 response.end();
65 })
66 break;
67 case "swu-symbol-png":
68 swu.symbolPng(parts[4]).then ( res => {
69 response.writeHead(200, { "Content-Type": "image/png" })
70 response.write(res)
71 response.end();
72 })
73 break;
74 case "swu-symbol-normalize":
75 swu.symbolNormalize(parts[4]).then ( res => {
76 response.writeHead(200, { "Content-Type": "text/plain; charset=utf-8" })
77 response.write(res)
78 response.end();
79 })
80 break;
81 case "swu-sign-svg":
82 swu.signSvg(parts[4]).then ( res => {
83 response.writeHead(200, { "Content-Type": "image/svg+xml; charset=utf-8" })
84 response.write(prefix)
85 response.write(res)
86 response.end();
87 })
88 break;
89 case "swu-sign-png":
90 swu.signPng(parts[4]).then ( res => {
91 response.writeHead(200, { "Content-Type": "image/png" })
92 response.write(res)
93 response.end();
94 })
95 break;
96 case "swu-sign-normalize":
97 swu.signNormalize(parts[4]).then ( res => {
98 response.writeHead(200, { "Content-Type": "text/plain; charset=utf-8" })
99 response.write(res)
100 response.end();
101 })
102 break;
103 default:
104 fs.readFile("server/index.html", (err, res) => {
105 response.writeHead(200, { "Content-Type": "text/html; charset=utf-8" })
106 response.write(err || res);
107 response.end();
108 });
109 }
110})
111
112server.listen(4200);
113
114console.log("Listening at http://localhost:4200")