| 12345678910111213141516171819202122232425262728 |
- //server.js 專案起始點
- const express = require("express");
- const cookieSession = require("cookie-session");
- const dotenv = require('dotenv').config();
- const db = require('./pass_db.js');
- db.users_init_fixed()
- db.vote_init_random(5); // you COULD change this, but you could also leave it alone?
- const app = express();
- const PORT = process.env.PORT || 8000; // 允許從 .env 文件或環境變量中設定端口
- app.use(express.static("static"))
- app.set('view engine', 'ejs')
- app.use(cookieSession({
- name: 'session',
- keys: [process.env.SESSION_KEY || 'default_session_key'],
- maxAge: 24 * 60 * 60 * 1000 // 24 hours
- }))
- // 使用 Express 內建的中間件來解析 JSON 和 URL 編碼的資料
- app.use(express.json());
- app.use(express.urlencoded({ extended: true }));
- const apiRouter = require("./routers/api")
- app.use('/api/v1', apiRouter);
- app.listen(PORT, () => console.log(`server should be running at http://localhost:${PORT}/`))
|