20 lines
631 B
JavaScript
20 lines
631 B
JavaScript
const { SERVER_HOST, SERVER_PORT, MONGDB_URL } = require('./config')
|
|
const express = require('express')
|
|
const mongoose = require('mongoose')
|
|
mongoose.connect(MONGDB_URL, (error) => {
|
|
if (error) {
|
|
console.error(error)
|
|
} else {
|
|
console.info('mongodb connected successfully')
|
|
}
|
|
})
|
|
const app = express()
|
|
app.use(express.static('public'))
|
|
app.set('view engine', 'pug')
|
|
app.get('/', async (req, res) => {
|
|
res.render('index', { title: '文件分享服务器' })
|
|
})
|
|
const server = app.listen(SERVER_PORT, SERVER_HOST, () => {
|
|
console.info(`server is running at http://${SERVER_HOST}:${SERVER_PORT}`)
|
|
})
|