-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed the issue of broken when not given the default parameter.
- Loading branch information
1 parent
a1d460a
commit e0f3574
Showing
5 changed files
with
81 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const express = require('express'); | ||
const path = require('path'); | ||
const bodyParser = require('body-parser'); | ||
|
||
const routes = require('./routes/index'); | ||
|
||
const { | ||
slogger, | ||
port, | ||
} = require('./config'); | ||
const requestLog = require('../../../index'); | ||
|
||
const app = express(); | ||
app.enable('trust proxy'); | ||
|
||
// view engine setup | ||
app.set('port', port); | ||
app.use(requestLog({})); | ||
|
||
app.use(bodyParser.json({limit: '1mb'})); | ||
app.use(bodyParser.urlencoded({ | ||
extended: false, | ||
limit: '1mb' | ||
})); | ||
|
||
|
||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
app.use('/', routes); | ||
|
||
// catch 404 and forward to error handler | ||
app.use(function(req, res, next) { | ||
const err = new Error('Not Found:' + req.path); | ||
err.status = 404; | ||
next(err); | ||
}); | ||
|
||
// error handlers | ||
app.use(function(err, req, res, next) { | ||
const status = err.status; | ||
if (status === 404) { | ||
return res.status(404).send(err.message || '未知异常'); | ||
} | ||
res.status(status || 500); | ||
slogger.error('发现应用未捕获异常', err); | ||
res.send({ | ||
msg: err.message || '未知异常', | ||
code: 0xffff | ||
}); | ||
}); | ||
|
||
|
||
module.exports = app; |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const app = require('../express/src/app-no-param'); | ||
|
||
const request = require('supertest'); | ||
describe('no session test:',function() { | ||
it('sucess when request / ok',function(done) { | ||
request(app) | ||
.get('/') | ||
.expect(200) | ||
.end(function(err) { | ||
if (err) { | ||
return done(err); | ||
} | ||
done(); | ||
}); | ||
}); | ||
}); |