Files
mixly3/static-server/static-server.js

22 lines
696 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const http = require('http');
const express = require('express');
const path = require('path');
const apiRoutes = require('./api.js');
const StaticServer = {};
StaticServer.run = (port) => {
const app = express();
app.use(express.static(path.resolve(__dirname, '../')));
app.use('/api/', apiRoutes);
const httpServer = http.createServer(app);
httpServer.listen(port);
console.log('Static服务器正在运行 [端口 - ' + port + ', http]...');
console.log('访问地址http://127.0.0.1:' + port);
StaticServer.server = httpServer;
StaticServer.app = app;
StaticServer.port = port;
StaticServer.protocol = 'http';
}
module.exports = StaticServer;