-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
51 lines (37 loc) · 1.18 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import express, { json } from 'express'
import { ykw2Router } from './routes/ykw_2.js'
import { client } from './client/client.js'
import cors from 'cors'
import fs from 'fs'
import path from 'path'
const PORT = process.env.PORT
const app = express()
app.disable('x-powered-by')
app.use(json())
app.use(cors())
app.use(express.static('public'))
app.use((req, res, next) => {
if (req.originalUrl != '/favicon.ico') {
console.log(Date.now(), `: ${req.method} ${req.originalUrl}`)
const log = `${Date.now()} : ${req.method} ${req.originalUrl}\n`
fs.appendFile(path.join('./access.log'), log, (err) => {
if (err) {
console.error('Error:', err)
}
})
next()
}
})
// app.use('/ykw1', ykw1Router)
app.use('/ykw2', ykw2Router)
// app.use('/ykw3', ykw3Router)
// app.use('/ykwb', ykwBlastersRouter)
app.use((req, res) => {
res.status(404).send({ res: `Error 404: ${req.url}`})
})
app.use('/', client)
app.listen(PORT, () => {
console.log('---------------------------------------')
console.log(`Servidor encendido en el puerto ${PORT}`)
console.log('---------------------------------------')
})