代码拉取完成,页面将自动刷新
同步操作将从 liweisadleader/CodeCraft 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/**
* Created by william on 26.03.15.
*/
var express = require('express'),
http = require('http'),
favicon = require('serve-favicon'),
morgan = require('morgan'),
compression = require("compression"),
bodyParser = require('body-parser'),
methodOverride = require('method-override'),
cookieParser = require('cookie-parser'),
cookieSession = require('cookie-session'),
config = require('./config'),
mongoose = require('mongoose'),
passport = require('passport'),
protectJSON = require('./lib/protectJSON'),
security = require('./lib/security');
var app = express();
// Get connection to MongoDB
var connection = mongoose.connect(config.mongo.dbUrl + '/' + config.security.dbName);
/***** Server set up *****/
app.use(express.static(config.server.distFolder)); // serve application files
app.use(config.server.staticUrl, express.static(config.server.distFolder)); // serve static files
app.use(favicon(config.server.distFolder + '/favicon.png')); // serve favicon
app.use(protectJSON); // apply JSON protection
app.set('port', config.server.listenPort); // set up port number
app.set('securePort', config.server.securePort); // set up secure port number
app.use(morgan('combined')); // set up logger
app.use(compression()); // apply compression to all request
app.use(config.server.staticUrl, compression()); // apply compression to static files
app.use(bodyParser.json()); // set up JSON paser
app.use(methodOverride()); // overwrite request header
app.use(cookieParser(config.server.cookieSecret)); // set up cookie paser with secrets
// provide guests sessions
app.use(cookieSession({name: config.server.cookieName, secret: config.server.cookieSecret}));
// Initialize PassportJS
app.use(passport.initialize());
// Use Passport's session authentication strategy - this stores the logged in user in the session and will now run on any request
app.use(passport.session());
// Add Mongo strategy for authentication
security.initialize(config.mongo.dbUrl, config.security.dbName, config.security.usersCollection);
app.use(function(req, res, next) {
var t="[" + new Date().toUTCString() + "]";
if (req.user) {
console.log(t, "- Current User:", req.user.username);
} else {
console.log(t, "- Unauthenticated");
}
next();
});
// Basic access api
app.post('/login', security.login);
app.post('/logout', security.logout);
app.get('/current-user', security.sendCurrentUser);
// Api endpoints
require('./routes')(app, security);
// Handle unmatched api
app.get('/api/*', function(req, res) {
res.status(400).json({ message: 'Bad request.' });
});
app.get('/*',function(req, res) {
res.sendFile('index.html', { root: config.server.distFolder });
});
// Start server
http.createServer(app).listen(config.server.listenPort, config.server.ip, function() {
console.log("Code Craft - listening on port " + config.server.listenPort);
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。