From 244a8804960308f3ada677cbfc61715502f5aa21 Mon Sep 17 00:00:00 2001 From: Pratik Borsasdiya Date: Sun, 27 May 2018 15:31:09 +0530 Subject: [PATCH] Add NodeJs development server --- .gitignore | 2 -- README.md | 18 ++++++++++++------ node-dev-server.js | 47 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 ++- 4 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 node-dev-server.js diff --git a/.gitignore b/.gitignore index 61d78de..c2658d7 100755 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ node_modules/ -dist/local.js -*/local.js diff --git a/README.md b/README.md index cfd4ae2..156d946 100644 --- a/README.md +++ b/README.md @@ -8,20 +8,26 @@ Vali is a free, modular and easy to customize admin theme built using [Bootstrap Run a `npm install` command in project root directory to install and build dependencies. If you don't want to edit theme you can use the compiled files inside `docs` folder. -Use `npm run dev` task to watch and compile source files. -Use `npm run build` task to compile all source files. +Use `npm run dev` command to watch and compile source files. -## Customiztion -For more information about customizing theme colors please follow this [guide](http://pratikborsadiya.in/blog/vali-admin/). +Use `npm run build` command to compile all source files. + +Use `npm run start` command to start a development server using NodeJs. + +> **Note:** +> * The NodeJs server mentioned in `npm run start` command is for development purpose only. DONOT use it as a production server. + +## Customization +For more information about customizing theme colors please follow the official [documentation](http://pratikborsadiya.in/blog/vali-admin/). ## RTL Support -Please follow this [guide](http://pratikborsadiya.in/blog/vali-admin/) to enable RTL support. +Please follow the official [documentation](http://pratikborsadiya.in/blog/vali-admin/) to enable RTL support. ## Contributors * **[Pratik Borsadiya](http://pratikborsadiya.in)** - *Project Author* -See the list of [contributors](https://github.com/pratikborsadiya/vali-admin/graphs/contributors) who participated in this project. +List of [contributors](https://github.com/pratikborsadiya/vali-admin/graphs/contributors) who participated in this project. ## License diff --git a/node-dev-server.js b/node-dev-server.js new file mode 100644 index 0000000..0f2a68b --- /dev/null +++ b/node-dev-server.js @@ -0,0 +1,47 @@ +// Node JS development server for Vali Admin + +var http = require("http"), + url = require("url"), + path = require("path"), + fs = require("fs") + port = process.argv[2] || 8888; + +http.createServer(function(request, response) { + var uri = url.parse(request.url).pathname, + filename = path.join(process.cwd(), 'docs', uri); + + var extname = path.extname(filename); + var contentType = 'text/html'; + + switch (extname) { + case '.js': contentType = 'text/javascript'; break; + case '.css': contentType = 'text/css'; break; + case '.ico': contentType = 'image/x-icon'; break; + case '.svg': contentType = 'image/svg+xml'; break; + } + + fs.exists(filename, function(exists) { + if(!exists) { + response.writeHead(404, {"Content-Type": "text/plain"}); + response.write("404 Not Found\n"); + response.end(); + return; + } + + if (fs.statSync(filename).isDirectory()) filename += '/index.html'; + + fs.readFile(filename, "binary", function(err, file) { + if(err) { + response.writeHead(500, {"Content-Type": "text/plain"}); + response.write(err + "\n"); + response.end(); + return; + } + response.writeHead(200, {'Content-Type': contentType}); + response.write(file, "binary"); + response.end(); + }); + }); +}).listen(parseInt(port, 10)); + +console.log("Server is running on http://localhost:" + port ); diff --git a/package.json b/package.json index 011f5b7..2c5183d 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ }, "scripts": { "dev": "grunt watch", - "build": "grunt build" + "build": "grunt build", + "start": "node node-dev-server.js" }, "repository": { "type": "git",