Commit 4738ff88 by Leo Zheng

在本地部署服务器

parent d7757ee1
<config> <config>
<port>30016</port> <port>30016</port>
<host>192.168.0.132</host>
</config> </config>
\ No newline at end of file
...@@ -32,14 +32,13 @@ export class totalVisitorFlowByHourStrategy extends abstractDataStrategyLeft { ...@@ -32,14 +32,13 @@ export class totalVisitorFlowByHourStrategy extends abstractDataStrategyLeft {
* @returns 全景区各类每小时各类游客流量。 * @returns 全景区各类每小时各类游客流量。
*/ */
private getTotalVisitorFlowByHour(data: any, date: string) { private getTotalVisitorFlowByHour(data: any, date: string) {
console.log("here!");
const visitorCount: Map<string, Map<number, number>> = new Map(); const visitorCount: Map<string, Map<number, number>> = new Map();
visitorCount.set('儿童', new Map()); visitorCount.set('儿童', new Map());
visitorCount.set('其他', new Map()); visitorCount.set('其他', new Map());
visitorCount.set('学生', new Map()); visitorCount.set('学生', new Map());
visitorCount.set('老人', new Map()); visitorCount.set('老人', new Map());
visitorCount.forEach((value) => { visitorCount.forEach((value, key) => {
for (let hour = 0; hour < 24; hour++) { for (let hour = 0; hour < 24; hour++) {
value.set(hour, 0); value.set(hour, 0);
} }
...@@ -60,7 +59,6 @@ export class totalVisitorFlowByHourStrategy extends abstractDataStrategyLeft { ...@@ -60,7 +59,6 @@ export class totalVisitorFlowByHourStrategy extends abstractDataStrategyLeft {
if (rowDateString == date) { if (rowDateString == date) {
visitorCount.set(row['订单游客类型'],visitorCount.get(row['订单游客类型']).set(rowHour, (visitorCount.get(row['订单游客类型']).get(rowHour) || 0) + 1)); visitorCount.set(row['订单游客类型'],visitorCount.get(row['订单游客类型']).set(rowHour, (visitorCount.get(row['订单游客类型']).get(rowHour) || 0) + 1));
console.log(row['订单游客类型'], 'set!');
} }
}); });
return visitorCount; return visitorCount;
......
...@@ -14,17 +14,18 @@ export async function initConfig() { ...@@ -14,17 +14,18 @@ export async function initConfig() {
if (!configInfo || !configInfo.config) console.log("xml中无配置加载"); if (!configInfo || !configInfo.config) console.log("xml中无配置加载");
else { else {
//必要配置 //必要配置
let integralConfig = ["port"]; let integralConfig = ["port", "host"];
checkConfig(integralConfig, configInfo.config); checkConfig(integralConfig, configInfo.config);
let {port} = configInfo.config; let {port, host} = configInfo.config;
systemConfig.port = parseInt(port[0]); systemConfig.port = parseInt(port[0]);
systemConfig.host = host[0];
} }
} catch(err) { } catch(err) {
// throw new BizError("服务器配置解析错误 请检查根目录下 serverConfig.xml 文件是否正确"); throw new Error("服务器配置解析错误 请检查根目录下 serverConfig.xml 文件是否正确");
} }
} }
......
...@@ -4,5 +4,5 @@ ...@@ -4,5 +4,5 @@
export class ServerConfig { export class ServerConfig {
port:number; port:number;
host:string;
} }
...@@ -9,47 +9,43 @@ import { httpErrorHandler } from '../middleware/httpErrorHandler'; ...@@ -9,47 +9,43 @@ import { httpErrorHandler } from '../middleware/httpErrorHandler';
import { DataExtractor } from "../util/dataExtractor"; import { DataExtractor } from "../util/dataExtractor";
export class httpServer { export class httpServer {
static createServer(port:number) { static createServer(port: number, host: string) {
var httpServer = express(); const httpServer = express();
httpServer.all('*',function (req, res, next) { httpServer.all('*', (req, res, next) => {
res.header('Access-Control-Allow-Origin', req.headers.origin); res.header('Access-Control-Allow-Origin', req.headers.origin);
res.header("Access-Control-Allow-Headers", "X-Requested-With"); res.header("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Authorization");
res.header('Access-Control-Allow-Headers', 'Content-Type'); res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS"); res.header('Access-Control-Allow-Credentials', 'true');
res.header('Access-Control-Allow-Credentials', true); res.header("X-Powered-By", '3.2.1');
res.header("X-Powered-By", ' 3.2.1'); if (req.method === 'OPTIONS') {
res.header("Authorization", 'Basic SzEyUlBDOksxMlJQQ1B3ZA=='); res.sendStatus(200);
if(req.method === 'OPTIONS'){ } else {
res.statusCode = 200; next();
res.end(); }
}else{ });
next();
}
});
httpServer.use(bodyParser.json({ limit: "10kb" }));
httpServer.use(bodyParser.json({limit:"10kb"})); httpServer.use(compression());
httpServer.use(compression())
httpServer.use(watch); httpServer.use(watch);
routers.setRouter(httpServer); routers.setRouter(httpServer);
httpServer.use(httpErrorHandler); httpServer.use(httpErrorHandler);
httpServer.use(express.static(path.join(__dirname, "../../img/")) ); httpServer.use(express.static(path.join(__dirname, "../../img/")));
httpServer.use(express.static(path.join(__dirname, "../../pdf/")) ); httpServer.use(express.static(path.join(__dirname, "../../pdf/")));
const root = path.join(__dirname, "../../public/") const root = path.join(__dirname, "../../public/");
httpServer.use(express.static(root)) httpServer.use(express.static(root));
httpServer.use(fallback('index.html', { root })) httpServer.use(fallback('index.html', { root }));
console.log('web listen on port:'+port);
console.log(`Server is listening at http://${host}:${port}`);
httpServer.listen(port, host, () => {
httpServer.listen(port); console.log(`Server started at http://${host}:${port}`);
console.log('server listen on port:'+port); });
DataExtractor.getInstance();
DataExtractor.getInstance();
return httpServer;
} return httpServer;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment