This repository has been archived by the owner on Jan 29, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(demo): upgrade demo-server, removing grunt integration
`grunt server` => `npm run start-demo`
- Loading branch information
Showing
6 changed files
with
48 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
module.exports = function (app, dir) { | ||
var url = require('url'), fs = require('fs'); | ||
|
||
app.get('/demo/', function(req, res) { | ||
app.get('/demo/', function (req, res) { | ||
function answer(code, data) { | ||
res.writeHead(code,{ | ||
'Content-Type':'text/html;charset=utf-8' | ||
res.writeHead(code, { | ||
'Content-Type' : 'text/html;charset=utf-8' | ||
}); | ||
res.end(data); | ||
}; | ||
|
||
var _get = url.parse(req.url, true).query; | ||
fs.readFile('./demo/index.htm', function(err, data) { | ||
fs.readFile('./demo/index.htm', function (err, data) { | ||
if (err) answer(404, ''); | ||
else answer(200, data); | ||
}); | ||
}); | ||
|
||
app.get('/demo/get_lang', function (req, res) { | ||
function answer(code, data) { | ||
res.writeHead(code,{ | ||
'Content-Type':'application/json;charset=utf-8', | ||
'Access-Control-Allow-Origin':'*', | ||
'Access-Control-Allow-Headers':'X-Requested-With' | ||
res.writeHead(code, { | ||
'Content-Type' : 'application/json;charset=utf-8', | ||
'Access-Control-Allow-Origin' : '*', | ||
'Access-Control-Allow-Headers' : 'X-Requested-With' | ||
}); | ||
res.end(data); | ||
}; | ||
} | ||
|
||
var _get = url.parse(req.url, true).query; | ||
fs.readFile('./demo/l10n/' + _get['lang'] + '.json', function(err, data) { | ||
fs.readFile('./demo/l10n/' + _get['lang'] + '.json', function (err, data) { | ||
if (err) answer(404, ''); | ||
else answer(200, data); | ||
}); | ||
|
||
}); | ||
|
||
// Example | ||
app.get('/this-is-an-express-server', function (req, res) { | ||
res.send(200); | ||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
var http = require('http'); | ||
var express = require('express'); | ||
var logger = require('morgan'); | ||
var methodOverride = require('method-override'); | ||
var bodyParser = require('body-parser'); | ||
var multer = require('multer'); | ||
var errorHandler = require('errorhandler'); | ||
|
||
// Create express facility. | ||
var app = express() | ||
// Create a HTTP server object. | ||
var server = require('http').createServer(app); | ||
var routes = require('./demo/server_routes'); | ||
|
||
app.configure(function () { | ||
app.use(express.logger('dev')); | ||
app.use(express.bodyParser()); | ||
app.use(express.methodOverride()); | ||
app.use(express.errorHandler()); | ||
app.use(express.static(__dirname)); | ||
app.use(app.router); | ||
require('./demo/server_routes')(app, __dirname); | ||
}); | ||
|
||
module.exports = server; | ||
var app = express(); | ||
app.set('port', process.env.PORT || 3005); | ||
app.use(logger('dev')); | ||
app.use(methodOverride()); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({extended : true})); | ||
app.use(express.static(__dirname)); | ||
routes(app, __dirname); | ||
app.use(errorHandler()); | ||
|
||
// Override: Provide an "use" used by grunt-express. | ||
module.exports.use = function () { | ||
app.use.apply(app, arguments); | ||
}; | ||
app.listen(app.get('port'), function () { | ||
console.log('Express server listening on port ' + app.get('port')) | ||
}); |