Skip to content

Commit a339e11

Browse files
Refactoring: added dsit for ui, moved statics to fs in server
1 parent d3da25e commit a339e11

7 files changed

Lines changed: 24 additions & 8 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
<body>
88
<div id="mount-node"></div>
99
<div id="drawing"></div>
10-
<script src="./bundle.js" type="text/javascript"></script>
10+
<script src="bundle.js" type="text/javascript"></script>
1111
</body>
1212
</html>

src/public/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const config = {
1010
entry: __dirname + '/js/index.js',
1111
devtool: 'source-map',
1212
output: {
13-
path: __dirname,
13+
path: __dirname + '/dist',
1414
filename: outputFile,
1515
library: libraryName,
1616
libraryTarget: 'umd',

src/server/api/api.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const requestHandler = (url, response) => {
2+
//TODO: handle API here
3+
return response.end();
4+
};
5+
6+
module.exports = {
7+
requestHandler
8+
};
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require('fs');
22

33
const PATH = {
4-
PUBLIC: 'src/public/',
4+
PUBLIC: 'src/public/dist/',
55
PAGE: 'index.html'
66
};
77

@@ -19,9 +19,7 @@ const responseWithFile = function(options, response) {
1919
});
2020
};
2121

22-
const requestHandler = (request, response) => {
23-
const url = request.url.substr(1);
24-
22+
const requestHandler = (url, response) => {
2523
if (!url) {
2624
return responseWithFile(
2725
{

src/server/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
const WebSocketServer = require('websocket').server;
22
const http = require('http');
3-
const statics = require('./statics');
3+
const statics = require('./fs/statics');
4+
const api = require('./api/api');
45
const projectSourceWatcher = require('./project-source-watcher');
56

67
const PORT = 2018;
78
const PROJECT_DIR = 'example-project'; //get as param to server script
89

9-
const httpServer = http.createServer(statics.requestHandler);
10+
const httpServer = http.createServer((request, response) => {
11+
const url = request.url.substr(1);
12+
13+
if (url.startsWith('api')) {
14+
return api.requestHandler(url, response);
15+
}
16+
17+
statics.requestHandler(url, response);
18+
});
19+
1020
httpServer.listen(PORT, () => {
1121
console.log(new Date() + `Server is listening localhost: ${PORT}.`);
1222
});

0 commit comments

Comments
 (0)