filesharing/server.js

20 lines
633 B
JavaScript
Raw Normal View History

2022-08-26 04:34:04 +00:00
const { SERVER_HOST, SERVER_PORT, MONGODB_URL } = require('./config')
2022-08-25 06:34:16 +00:00
const express = require('express')
const mongoose = require('mongoose')
2022-08-26 04:34:04 +00:00
mongoose.connect(MONGODB_URL, (error) => {
if (error) {
console.error(error)
} else {
console.info('mongodb connected successfully')
}
})
2022-08-25 06:34:16 +00:00
const app = express()
2022-08-26 04:32:33 +00:00
app.use(express.static('public'))
2022-08-25 06:43:38 +00:00
app.set('view engine', 'pug')
app.get('/', async (req, res) => {
2022-08-26 04:32:33 +00:00
res.render('index', { title: '文件分享服务器' })
2022-08-25 06:34:16 +00:00
})
const server = app.listen(SERVER_PORT, SERVER_HOST, () => {
console.info(`server is running at http://${SERVER_HOST}:${SERVER_PORT}`)
2022-08-25 06:34:16 +00:00
})