| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- const express = require('express');
- const path = require('path');
- const app = express();
- const { getLocale } = require('./libs/utils');
- const config = require('./config/app')
- // 设置视图引擎为EJS
- app.set('view engine', 'ejs');
- // 设置视图目录
- app.set('views', path.join(__dirname, 'views'));
- app.use(express.static(config.STATIC_DIR));
- app.use(express.static(path.join(__dirname, 'dist')));
- app.use('/thumbs/v1', require('./routes/res/thumbs'));
- app.use('/', require('./routes/index'));
- app.use('/proxy', require('./routes/proxy'));
- // catch 404 and forward to error handler
- app.use(function (req, res) {
- // 设置状态码为404
- res.status(404);
- // res.sendFile(path.join(__dirname, '404.html'));
- res.render('404', { title: '404 Error', description: 'PAGE NOT FOUND' });
- });
- // error handler
- app.use(function (err, req, res, next) {
- // set locals, only providing error in development
- res.locals.message = err.message;
- res.locals.error = req.app.get('env') === 'development' ? err : {};
- console.log("error:" + err);
- // render the error page
- res.status(err.status || 500);
- res.render('404', { title: '404 Error', description: 'PAGE NOT FOUND' });
- });
- // 启动服务器,监听3000端口
- const PORT = process.env.PORT || 3000;
- app.listen(PORT, () => {
- console.log(`Server is running on http://localhost:${PORT}`);
- });
|